1

I have a map with a symbol on it, that I introduce using this following code:

symbolOptions = SymbolOptions()
                .withLatLng(LatLng(localImageObject.locationLat, localImageObject.locationLong))
                .withIconImage(DERE_PIN)
                .withIconSize(1.3f)
                .withZIndex(10)
                .withDraggable(true)

symbolManager.create(symbolOptions)

So currently my map has one symbol on it. I'd like it to be so when the user long presses the map or clicks, the symbol would change it's location and not create a new one. How can I do this?

Nirav Bhavsar
  • 2,133
  • 2
  • 20
  • 24
Tsabary
  • 3,119
  • 2
  • 24
  • 66

2 Answers2

4

The options class of an annotation is only used for intialisation. The actual annotation is returned when you call create. This is the object you can use later on to update the location:

val symbol = symbolManager.create(symbolOptions);
symbol.setGeometry(Point.fromLngLat(lonValue, latValue));
Tobrun
  • 18,291
  • 10
  • 66
  • 81
0

Use the MapboxMap.OnMapClickListener interface and implement the method onMapClick to delete the symbol before adding a new on the map.

private SymbolManager symbolManager;
private List<Symbol> symbols //init

    @Override
    public boolean onMapClick(@NonNull LatLng point) {
        if(!symbols.isEmpty()) {
            symbolManager.delete(symbols);
            symbols.clear();
        }
        if(symbolManager == null) {
            symbolManager = new SymbolManager(mapView, map, map.getStyle());
        }

        symbolOptions = SymbolOptions()
                .withLatLng(LatLng(localImageObject.locationLat, 
        localImageObject.locationLong))
                .withIconImage(DERE_PIN)
                .withIconSize(1.3f)
                .withZIndex(10)
                .withDraggable(true)

        symbols.add(symbolManager.create(symbolOptions))
    }