mapbox-maps-flutter
mapbox-maps-flutter copied to clipboard
How to get the coordinates of center of Map screen?
I want to get the location of the center of Map screen which I am unable to see an option to get. Is there any option by which we can track the coordinates after scroll ??
@arslankaleem7229 You can use MapboxMap.coordinateForPixel() to get the coordinates of a location in the center of the map.
Thanks @evil159 . Its working fine. But there as issue with this I am using screen center using MediaQuery for giving x and y but the coordinates I am getting in return are not accurate
double screenWidth = MediaQuery.of(context).size.width;
double screenHeight = MediaQuery.of(context).size.height;
double middleX = screenWidth / 2;
double middleY = screenHeight / 2;
mapboxMap.coordinateForPixel(mapbox.ScreenCoordinate(
x: middleX.roundToDouble(),
y: middleY.roundToDouble())
).then((value) async {
print(value)
});
@arslankaleem7229
void _onCameraChanged() async { final center = await _controller!.getCameraState(); final centerLatLng = LatLng( (center.center['coordinates'] as List)[1], (center.center['coordinates'] as List)[0], ); }