1

I would like to add a list of points to my mapbox mapin my Android app. I am able to draw polygons and lines to my map, but there is no function to draw a single point to the map. Is there a solution to draw 1000+ points to the mapbox map?

Something like this: this or this

I would like to do this for Android and refresh the points and change their position.

2 Answers 2

1

You can add a single marker using the addMarker() method (full example). If you need more complex views, you can also create view-based markers (full example).

Sign up to request clarification or add additional context in comments.

Comments

0

I was looking at documentation and it looks like you can accomplish what you want using the annotations plugin for mapbox! (https://docs.mapbox.com/android/plugins/overview/annotation/#options)

Assuming you already have the dependency initialized there are a few steps you need to do to start using this annotation plug-in!

The documentation goes into great detail on how to use this so that is really helpful, but I'll include an example for using this feature to create an annotation. All of the code below is taken from the documentation and pieced together as described. Hope this helps!

First add this code snippet to your gradle file

repositories {
  mavenCentral()
}

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

Next add this code to your fragment/activity you have your mapbox created in.

    @Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
    mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
      @Override
      public void onStyleLoaded(@NonNull Style style) {

        // Use a layer manager here
        // create symbol manager object
        SymbolManager symbolManager = new SymbolManager(mapView, mapboxMap, style);

        // add click listeners if desired
        symbolManager.addClickListener(symbol ->

        );

        symbolManager.addLongClickListener(symbol -> {

        });

        // set non-data-driven properties, such as:
        symbolManager.setIconAllowOverlap(true);
        symbolManager.setIconTranslate(new Float[]{-4f,5f});
        symbolManager.setIconRotationAlignment(ICON_ROTATION_ALIGNMENT_VIEWPORT);

        symbolManager.setIconAllowOverlap(true);
        symbolManager.setIconIgnorePlacement(true);

        // Add symbol at specified lat/lon
        Symbol symbol = symbolManager.create(new SymbolOptions()
            .withLatLng(new LatLng(60.169091, 24.939876))
            .withIconImage(ICON_ID)
            .withIconSize(2.0f));

       }
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.