3

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))
                );
            }
        })

    }
wawanopoulos
  • 9,614
  • 31
  • 111
  • 166
  • Hey wawanopoulos, I'm no Kotlin expert (though I've spent extensive time working with Mapbox using Java). At a glance, your code looks fine to me. That said, while it is extremely unlikely you're making the same mistake that I once did (mixing up my lat/lng values), perhaps hard-coding in a latitude and longitude when instantiating the `LatLng` you're using in `.withLatLng()` might confirm the coordinate you're using is where you expect it to be. – Tom Larcher Oct 03 '19 at 00:16

1 Answers1

0

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))
            )
Moritz
  • 1,710
  • 1
  • 8
  • 13