Skip to content

Drag marker and get new position #28929

@ElHombreSinNombre

Description

@ElHombreSinNombre

In Flutter I have a map that take the device position with help of location plugin. Then i use this position to show marker in Google map with help of Google Maps Flutter plugin.

The code is similar to

child: GoogleMap(
        mapType: MapType.hybrid,
        initialCameraPosition: CameraPosition(
          target: LatLng(lat, lng),
          zoom: 5,
        ),
        markers: Set<Marker>.of(
          <Marker>[
            Marker(
              draggable: true,
              markerId: MarkerId("1"),
              position: LatLng(lat, lng),
              icon: BitmapDescriptor.defaultMarker,
              infoWindow: const InfoWindow(
                title: 'Usted está aquí',
              ),
            )
          ],
        ),
        onMapCreated: (GoogleMapController controller) {
          mapController = controller;
        },
      ))

If location plugin fails or take wrong data i need to have the option to reposition this marker. I use draggable: true to drag marker, but i need to take the new latitude and longitude for save it in database.

So the question is: Using the draggable how can i get the new latitude and longitude?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions