0
votes

I am currently developing android map using mapbox sdk, and I want to add multiple markers when user click on one button. and I type below in my onStyleLoaded but it's not showing anything

List<Feature> symbolLayerIconFeatureList = new ArrayList<>();
            symbolLayerIconFeatureList.add(Feature.fromGeometry(
                    Point.fromLngLat(31.995560, 34.767070)));
            symbolLayerIconFeatureList.add(Feature.fromGeometry(
                    Point.fromLngLat(31.995979, 34.744110)));
            symbolLayerIconFeatureList.add(Feature.fromGeometry(
                    Point.fromLngLat(31.995010, 34.767380)));
            style.addImage("charge-icon-id", BitmapFactory.decodeResource(
                    MapboxNavigationActivity.this.getResources(), R.drawable.map_marker_dark));

style.addSource(new GeoJsonSource("charge-source-id",
                          FeatureCollection.fromFeatures(symbolLayerIconFeatureList)));
SymbolLayer destinationSymbolLayer = new SymbolLayer("charge-layer-id", "charge-source-id");
destinationSymbolLayer.withProperties(iconImage("charge-icon-id"),
          iconAllowOverlap(true),
          iconIgnorePlacement(true)
          );
style.addLayer(destinationSymbolLayer);

May I ask what are the problem?

1

1 Answers

0
votes

It's a bit tough to say without some more context/information, but I'm guessing that the issue is related to the order in which you're adding the source, layer, and image. Take a look at this example: https://docs.mapbox.com/android/maps/examples/marker-symbol-layer/

You'll want to add the image, source, and layer before the style is loaded. You can then make additional adjustments/add data when the style is loaded using the onStyleLoaded listener.

Disclaimer: I work at Mapbox.