Ahmed Wagdi
Ahmed Wagdi

Reputation: 4391

Adding marker to mapbox in flutter application

I've created a map using Mapbox API in flutter application, and used the animateCamera method which working perfectly, but I need to add a marker on the specific location after moving the camera .. here is the code I've used :

  Future<void> movingCameraToLocation(double latitude, double longitude) async {
    await mapController.animateCamera(
      CameraUpdate.newCameraPosition(
        CameraPosition(
          bearing: 270.0,
          target: LatLng(latitude, longitude),
          tilt: 30.0,
          zoom: 21.0,
        ),
      ),
    );
  }

now how to add a marker on the Latlng used in here ?

Upvotes: 1

Views: 2452

Answers (1)

Moritz
Moritz

Reputation: 1790

I would recommend to take a look at this example that is placing a symbol at a specific position of your map in flutter.

The class PlaceSymbolBodyState implements the method _add which adds a symbol at the specified location center:

  void _add(String iconImage) {
    controller.addSymbol(
      SymbolOptions(
        geometry: LatLng(
          center.latitude,
          center.longitude,
        ),
        iconImage: iconImage,
      ),
    );
    setState(() {
      _symbolCount += 1;
    });
  }

Upvotes: 2

Related Questions