skip to Main Content

I need to get the coordinates under my custom marker here is an image of my custom marker

custom marker image I am using stack to place my custom maker on specfic postion from top and left now I need the coordinates under my custom marker to get the location.

final GoogleMapController gmController =
  await controller.future;
LatLngBounds visibleRegion =
  await gmController.getVisibleRegion();
LatLng centerLatLng = LatLng(
(visibleRegion.northeast.latitude +
        visibleRegion.southwest.latitude) /
    2,
(visibleRegion.northeast.longitude +
        visibleRegion.southwest.longitude) /
    2,
);

print(centerLatLng);

this above code is used to get center coordinates of map any help would be appriciated.

2

Answers


  1.         GoogleMap(
              initialCameraPosition: CameraPosition(target: _initialCameraPosition),
              mapType: MapType.normal,
              onMapCreated: (GoogleMapController _cntlr) {
                _onMapCreated(_cntlr);
              },
              myLocationEnabled: true,
              onTap: (LatLng latLng) {
                if (_controller != null) {
                  _controller!.animateCamera(
                    CameraUpdate.newCameraPosition(CameraPosition(target: LatLng(latLng.latitude, latLng.longitude), zoom: 15)),
                  );
                }
                _handleTap(latLng);
              },
              markers: _markers,
              gestureRecognizers: Set()
                ..add(
                  Factory<PanGestureRecognizer>(
                    () => PanGestureRecognizer(),
                  ),
                )
                ..add(Factory<ScaleGestureRecognizer>(
                    () => ScaleGestureRecognizer()))
                ..add(
                  Factory<TapGestureRecognizer>(
                    () => TapGestureRecognizer(),
                  ),
                )
                ..add(
                  Factory<VerticalDragGestureRecognizer>(
                    () => VerticalDragGestureRecognizer(),
                  ),
                ),
            ),
    
    
       HandleTap method will give you lat long.
    
    _handleTap(LatLng point) {
       latLng = "${num.parse(point.latitude.toStringAsFixed(6))},${num.parse(point.longitude.toStringAsFixed(6))}";
       print("LAT ::: LNG ${latLng}");
     } 
    
    Login or Signup to reply.
  2. To get the latitude and longitude (LatLng) of a specific position on the screen, you can use the GoogleMapController.getLatLng method.

     LatLng _getLatLng(Offset offset) async {
        return await _mapController.getLatLng(offset);
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search