com.mapbox.mapboxsdk.annotations.MarkerOptions Java Examples

The following examples show how to use com.mapbox.mapboxsdk.annotations.MarkerOptions. 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: PrkngDataDownloadTask.java    From android with MIT License 6 votes vote down vote up
protected void drawRadius(LatLng center, LatLng northWest) {
    final LatLng realNW = vMap.fromScreenLocation(new PointF(0, 0));
    final LatLng realCenter = vMap.getLatLng();

    vMap.addMarker(new MarkerOptions().position(northWest));
    vMap.addMarker(new MarkerOptions().position(center));
    vMap.addMarker(new MarkerOptions().position(realNW));
    vMap.addMarker(new MarkerOptions().position(realCenter));

    vMap.addPolyline(new PolylineOptions()
            .add(new LatLng[]{center, northWest})
            .color(Color.GREEN)
            .width(5));

    vMap.addPolyline(new PolylineOptions()
            .add(new LatLng[]{realCenter, realNW})
            .color(Color.YELLOW)
            .width(5));
}
 
Example #2
Source File: NavigationMapRouteActivity.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
@Override
public void onMapLongClick(@NonNull LatLng point) {
  if (originMarker == null) {
    originMarker = mapboxMap.addMarker(new MarkerOptions().position(point));
  } else if (destinationMarker == null) {
    destinationMarker = mapboxMap.addMarker(new MarkerOptions().position(point));
    Point originPoint = Point.fromLngLat(
      originMarker.getPosition().getLongitude(), originMarker.getPosition().getLatitude());
    Point destinationPoint = Point.fromLngLat(
      destinationMarker.getPosition().getLongitude(), destinationMarker.getPosition().getLatitude());
    requestDirectionsRoute(originPoint, destinationPoint);
    mapboxMap.removeMarker(originMarker);
    mapboxMap.removeMarker(destinationMarker);
  } else {
    originMarker = null;
    destinationMarker = null;
    navigationMapRoute.removeRoute();
  }
}
 
Example #3
Source File: DownloadPinsTask.java    From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #4
Source File: MapUtils.java    From android with MIT License 5 votes vote down vote up
public static Marker addSearchMarker(MapView mapView, LatLng latLng, Icon searchIcon) {
    final JsonSnippet snippet = new JsonSnippet.Builder()
            .search()
            .build();
    return mapView.addMarker(new MarkerOptions()
            .snippet(JsonSnippet.toJson(snippet))
            .position(latLng)
            .icon(searchIcon)
    );
}
 
Example #5
Source File: MapUtils.java    From android with MIT License 5 votes vote down vote up
public static void addCheckinMarkerIfAvailable(MapView mapView, Icon checkinIcon) {
    final CheckinData checkin = PrkngPrefs.getInstance(mapView.getContext()).getCheckinData();
    if (checkin != null) {
        final JsonSnippet snippet = new JsonSnippet.Builder()
                .checkin()
                .build();
        mapView.addMarker(new MarkerOptions()
                .icon(checkinIcon)
                .snippet(JsonSnippet.toJson(snippet))
                .position(checkin.getLatLng()));
    }
}
 
Example #6
Source File: MapUtils.java    From android with MIT License 5 votes vote down vote up
public static MarkerOptions extractMarkerOptions(Marker marker) {
    final MarkerOptions options = new MarkerOptions();
    if (marker != null) {
        options.position(marker.getPosition())
                .icon(marker.getIcon())
                .title(marker.getTitle())
                .snippet(marker.getSnippet());
    }

    return options;
}
 
Example #7
Source File: NavigationMapboxMap.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@NonNull
private Marker createMarkerFromIcon(Context context, Point position) {
  LatLng markerPosition = new LatLng(position.latitude(),
    position.longitude());
  Icon markerIcon = ThemeSwitcher.retrieveThemeMapMarker(context);
  return mapboxMap.addMarker(new MarkerOptions()
    .position(markerPosition)
    .icon(markerIcon));
}
 
Example #8
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-example with Apache License 2.0 5 votes vote down vote up
private void setCurrentMarkerPosition(LatLng position) {
    if (position != null) {
        if (currentMarker == null) {
            MarkerOptions markerOptions = new MarkerOptions()
                    .position(position);
            currentMarker = mapboxMap.addMarker(markerOptions);
        } else {
            currentMarker.setPosition(position);
        }
    }
}
 
Example #9
Source File: EndNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void drawPaella() {
  Icon paellaIcon = IconFactory.getInstance(this).fromResource(R.drawable.paella_icon);
  paella = navigationView.retrieveNavigationMapboxMap().retrieveMap().addMarker(new MarkerOptions()
    .position(new LatLng(37.760615, -122.424306))
    .icon(paellaIcon)
  );
}
 
Example #10
Source File: MockNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Override
public void onMapClick(@NonNull LatLng point) {
  if (destination == null) {
    destination = Point.fromLngLat(point.getLongitude(), point.getLatitude());
  } else if (waypoint == null) {
    waypoint = Point.fromLngLat(point.getLongitude(), point.getLatitude());
  } else {
    Toast.makeText(this, "Only 2 waypoints supported", Toast.LENGTH_LONG).show();
  }
  mapboxMap.addMarker(new MarkerOptions().position(point));

  startRouteButton.setVisibility(View.VISIBLE);
  calculateRoute();
}
 
Example #11
Source File: RerouteActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Override
public void userOffRoute(Location location) {
  Point newOrigin = Point.fromLngLat(location.getLongitude(), location.getLatitude());
  getRoute(newOrigin, destination, location.getBearing());
  Snackbar.make(contentLayout, "User Off Route", Snackbar.LENGTH_SHORT).show();
  mapboxMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())));
}
 
Example #12
Source File: RerouteActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Override
public void onMapClick(@NonNull LatLng point) {
  if (!running || mapboxMap == null) {
    return;
  }

  mapboxMap.addMarker(new MarkerOptions().position(point));
  mapboxMap.setOnMapClickListener(null);

  Point newDestination = Point.fromLngLat(point.getLongitude(), point.getLatitude());
  mockLocationEngine.moveTo(newDestination);
  destination = Point.fromLngLat(point.getLongitude(), point.getLatitude());
  tracking = false;
}
 
Example #13
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-example with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #14
Source File: MarkerWrapper.java    From android with MIT License 4 votes vote down vote up
public MarkerOptions getMarkerOptions() {
    return markerOptions;
}
 
Example #15
Source File: MarkerWrapper.java    From android with MIT License 4 votes vote down vote up
public void setMarkerOptions(MarkerOptions markerOptions) {
    this.markerOptions = markerOptions;
}
 
Example #16
Source File: SpotsAnnotations.java    From android with MIT License 4 votes vote down vote up
public void addMarker(String featureId, MarkerOptions marker) {
    this.markers.put(marker, featureId);
}
 
Example #17
Source File: SpotsAnnotations.java    From android with MIT License 4 votes vote down vote up
public HashMap<MarkerOptions, String> getMarkers() {
    return markers;
}