want to find a center of 2 points and fit a map. I want to fit for all screen when I view on map. I draw route ready but it fit to 1 point only. please help me. this class is for map view for a flutter. I try to find plugin and solution more day but still not found.
GoogleMap(
mapType: MapType.normal,
markers: _markers,
// cameraTargetBounds: CameraTargetBounds(new LatLngBounds(
// northeast: LatLng(latFrom, logFrom),
// southwest: LatLng(latTo, logTo),
// )),
// minMaxZoomPreference: MinMaxZoomPreference(1, 15),
mapToolbarEnabled: true,
scrollGesturesEnabled: true,
zoomGesturesEnabled: true,
trafficEnabled: true,
compassEnabled: true,
indoorViewEnabled: true,
rotateGesturesEnabled: true,
tiltGesturesEnabled: true,
myLocationButtonEnabled: true,
myLocationEnabled: true,
polylines: _polyline,
// padding: EdgeInsets.all(20),
initialCameraPosition:
CameraPosition(
target: LatLng(latFrom, logFrom),
zoom: 10,
),
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
})
void _setMapFitToTour(Set<Polyline> p) {
double minLat = p.first.points.first.latitude;
double minLong = p.first.points.first.longitude;
double maxLat = p.first.points.first.latitude;
double maxLong = p.first.points.first.longitude;
p.forEach((poly) {
poly.points.forEach((point) {
if(point.latitude < minLat) minLat = point.latitude;
if(point.latitude > maxLat) maxLat = point.latitude;
if(point.longitude < minLong) minLong = point.longitude;
if(point.longitude > maxLong) maxLong = point.longitude;
});
});
mapController.moveCamera(CameraUpdate.newLatLngBounds(LatLngBounds(
southwest: LatLng(minLat, minLong),
northeast: LatLng(maxLat,maxLong)
), 20));
}
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