I'd like to scale google map zoom level based on the radius of the circle. Technically I want the user to see circle on map at optimum zoom level. I tried to get bounds and adjust camera position, but circle does not have any such bounds parameter..
GoogleMap(
onMapCreated: (GoogleMapController controller) {
controller.showMarkerInfoWindow(MarkerId("0"));
},
circles: Set.from([
Circle(
circleId: CircleId("0"),
center: LatLng(...),
radius: 1000,
)
]),
initialCameraPosition: CameraPosition(
target: LatLng(..),
**zoom: 15, // I want to scale zoom based on radius of circle.**
),
markers: {
Marker(
markerId: MarkerId("0"),
position: LatLng(..),
infoWindow: InfoWindow(title: ...)
)
},
),
),
Thanks in Advance.
After some search, found a solution here which is in java for android application.
dart/flutter code would be as follows:
double getZoomLevel(double radius) {
double zoomLevel = 11;
if (radius > 0) {
double radiusElevated = radius + radius / 2;
double scale = radiusElevated / 500;
zoomLevel = 16 - log(scale) / log(2);
}
zoomLevel = num.parse(zoomLevel.toStringAsFixed(2));
return zoomLevel;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With