Daisy One
Daisy One

Reputation: 11

How to add a single annotation / marker with Mapbox Maps SDK for Android in Java

So, I have problem converting kotlin to java lang from their guideline. I have tried it on many way such as converting kotlin to java file but still cannot got it.

I have this code which is work with no annotation / marker. I call this method in onCreateView

private void setMap() {
    mapView = view.findViewById(R.id.mapView);
    mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS);
}

Upvotes: 0

Views: 1227

Answers (1)

RickertBrandsen
RickertBrandsen

Reputation: 211

You could try to do something like this in your fragment

 /**
  * Create circle on the place of the point parameter on Earth
  *
  * @param mapView Mapbox's mapView
  * @param point on Earth   -> can be created like this "Point point = Point.fromLngLat(50.0, 50.0);"
  */
 public void createCircleAnnotation(MapView mapView, Point point) {
     
     AnnotationPlugin annotationApi = AnnotationPluginImplKt.getAnnotations(mapView);
     CircleAnnotationManager circleAnnotationManager = CircleAnnotationManagerKt.createCircleAnnotationManager(annotationApi, new AnnotationConfig());

     // circle annotations options
     CircleAnnotationOptions circleAnnotationOptions = new CircleAnnotationOptions()
             .withPoint(point)
             .withCircleRadius(8.0)
             .withCircleColor("#ee4e8b")
             .withCircleBlur(0.5)
             .withCircleStrokeWidth(2.0)
             .withCircleStrokeColor("#ffffff");

     circleAnnotationManager.create(circleAnnotationOptions);
 }

The method is placing single circle annotation on to certain point on the Earth defined by the point variable. The only two things, you need to do, is to provide mapbox's MapView into the parameter and the Point variable.

The truth is that docs are a bit inaccurate even for Kotlin (mainly because of the multiple versions especially v10 vs previous versions), but with the help of decompiling of Kotlin bytecode, it is kind of possible to find a solution to almost everything for Java

Upvotes: 2

Related Questions