Java Code Examples for com.mapbox.mapboxsdk.annotations.MarkerOptions#icon()
The following examples show how to use
com.mapbox.mapboxsdk.annotations.MarkerOptions#icon() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadPinsTask.java From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void renderPins(final PinData p) { // Note: Use a LinkedList here so we don't need contiguous memory // We were having some interesting memory problems with an ArrayList. final LinkedList<MarkerOptions> markers = new LinkedList<MarkerOptions>(); Iterator it = p.pins.entrySet().iterator(); while( it.hasNext() ) { Map.Entry pair = (Map.Entry)it.next(); final MarkerOptions marker = new MarkerOptions().position((LatLng)pair.getKey()); marker.title(p.map.getContext().getString(R.string.confirmations) + ": " + Integer.valueOf((int)pair.getValue()).toString()); marker.icon(Images.getCameraIcon()); marker.snippet("This is a camera."); markers.add(marker); } if( markers.size() != 0 ) { Log.d("GPS", "Trying to render pins: " + Integer.toString(markers.size())); Runnable clearPins = new Runnable() { public void run() { p.map.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(MapboxMap mapboxMap) { // We don't want to layer cameras on top mapboxMap.removeAnnotations(); mapboxMap.addMarkers(markers); Log.d("GPS", "Pins now on map: " + Integer.toString(mapboxMap.getAnnotations().size())); } }); } }; // Note: Pins *must* be cleared on the main thread. // This is because if a UI window (like the pin detail screen) is currently open // then only the thread that created it can destroy it. If we delete the pins from // the background while a UI window for the pin is open it crashes the app. Handler mainThread = new Handler(Looper.getMainLooper()); mainThread.post(clearPins); } }
Example 2
Source File: NavigationLauncherActivity.java From graphhopper-navigation-example with Apache License 2.0 | 4 votes |
@Override public void onPostExecuteGeocodingSearch(List<GeocodingLocation> locations) { clearGeocodingResults(); markers = new ArrayList<>(locations.size()); if (locations.isEmpty()) { onError(R.string.error_geocoding_no_location); return; } List<LatLng> bounds = new ArrayList<>(); Location lastKnownLocation = getLastKnownLocation(); if (lastKnownLocation != null) bounds.add(new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude())); for (GeocodingLocation location : locations) { GeocodingPoint point = location.getPoint(); MarkerOptions markerOptions = new MarkerOptions(); LatLng latLng = new LatLng(point.getLat(), point.getLng()); markerOptions.position(latLng); bounds.add(latLng); markerOptions.title(location.getName()); String snippet = ""; if (location.getStreet() != null) { snippet += location.getStreet(); if (location.getHousenumber() != null) snippet += " " + location.getHousenumber(); snippet += "\n"; } if (location.getCity() != null) { if (location.getPostcode() != null) snippet += location.getPostcode() + " "; snippet += location.getCity() + "\n"; } if (location.getCountry() != null) snippet += location.getCountry() + "\n"; if (location.getOsmId() != null) { snippet += "OSM-Id: " + location.getOsmId() + "\n"; if (location.getOsmKey() != null) snippet += "OSM-Key: " + location.getOsmKey() + "\n"; if (location.getOsmType() != null) snippet += "OSM-Type: " + location.getOsmType() + "\n"; } snippet += "\n\n Tap on info window\n to add point to route"; if (!snippet.isEmpty()) markerOptions.snippet(snippet); markerOptions.icon(IconFactory.getInstance(this.getApplicationContext()).fromResource(R.drawable.ic_map_marker)); markers.add(mapboxMap.addMarker(markerOptions)); } // For bounds we need at least 2 entries if (bounds.size() >= 2) { LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); boundsBuilder.includes(bounds); animateCameraBbox(boundsBuilder.build(), CAMERA_ANIMATION_DURATION, padding); } else if (bounds.size() == 1) { // If there is only 1 result (=>current location unknown), we just zoom to that result animateCamera(bounds.get(0)); } hideLoading(); }