1

Android studio tell me, that the markers in Mapbox are deprecated (API level 21+, mapbox-android-sdk:7.2.0). But in the official documentation the example is:

mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(48.85819, 2.29458))
.title("Eiffel Tower"));

Should I add markers this way or there is a new way of doing this?

Spongi
  • 501
  • 3
  • 10
  • 19
  • If you are using +v7.x of the Android Maps SDK, I'd recommend using the [Annotation Plugin](https://docs.mapbox.com/android/plugins/overview/annotation/) instead. – riastrad Jun 04 '19 at 20:02

3 Answers3

1

To add markers to your map, you have to use the annotation plugin

First, add the Gradle dependency

implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.8.0'

Then in your onMapReady method, you use SymbolManager to add a marker on the map

    override fun onMapReady(mapboxMap: MapboxMap) {
    mapboxMap.setStyle(Style.MAPBOX_STREETS) { style ->

    val symbolManager = SymbolManager(mapView, mapboxMap, style)
    symbolManager.iconAllowOverlap = true
    style.addImage("myMarker",BitmapFactory.decodeResource(resources,R.drawable.ic_maker))
   symbolManager.create(SymbolOptions()
                            .withLatLng(LatLng(-1.693314, 29.225241))
                            .withIconImage("myMarker")
                    )
        }
     }
David Kathoh
  • 191
  • 1
  • 9
0

This should work...

New mapbox version api has provided another api to add markers on map. You can do using style.addLayer(....) inside map ready function.

0

Hear is the mapbox Depricated Detail

This is the link to update mapbox

Plugin to handle annotations As of the 7.0.0 release of the Mapbox Maps SDK for Android, much of the code on this page has been deprecated. Classes such as Polygon, Polyline, and Marker will not longer be maintained. This also means classes such as PolygonOptions and PolylineOptions should not be used. Lastly, this also means that methods such as addPolygon(), addPolyline(), or addMarker() also should not be used.

If you plan to add any icons, text, lines, or polygons to the map, look into the Mapbox Annotation Plugin for Android. It simplifies annotations and provides additional flexibility for displaying data.

mehul chauhan
  • 1,792
  • 11
  • 26