Mapbox Android SDK: Add makers using symbolManager

Viewed 533

I'm trying to add multiple markers using Mapbox Android SDK and using symbolManager as recommended here.

I just create this function which is responsible to create one marker for each car object. I don't get any error but nothing is displayed on the map.

private fun displayCarsLayer(cars: MutableList<Car>) {

        mapView.getMapAsync(OnMapReadyCallback { mapboxMap ->
            for (car in cars) {
                val carLat = car.lat
                val carLng = car.lng
                // Add the marker to the map
                symbolManager.create(
                    SymbolOptions()
                    .withLatLng(LatLng(carLat, carLng))
                );
            }
        })

    }
1 Answers

This might be a bit late, but this probably has to do with the way you initialize symbolManager. Currently you are not initializing it.

Once the map and style are loaded, you can initialize the SymbolManager in the onMapReady callback:

val symbolManager = SymbolManager(mapView, mapboxMap, style)

Then you can go on with your code:

symbolManager.create(
                SymbolOptions()
                .withLatLng(LatLng(carLat, carLng))
            )
Related