I am using the google_maps_flutter package and the Zoom level for the myLocationButton, when pressed, is set to my last zoom level. I would like to reset the Zoom level when the myLocationButton is pressed.
This is the code for the Google Maps;
GoogleMap(
padding: EdgeInsets.only(bottom: _mapBottomPadding),
mapType: MapType.normal,
initialCameraPosition: _baseLocation,
myLocationButtonEnabled: true,
myLocationEnabled: true,
zoomControlsEnabled: true,
zoomGesturesEnabled: true,
// minMaxZoomPreference: const MinMaxZoomPreference(12, 14),
polylines: _polylineSet,
markers: _markersSet,
onMapCreated: (GoogleMapController controller) async {
if (!_controller.isCompleted) {
//first calling is false
//call "completer()"
_controller.complete(controller);
// setState(() {});
} else {
//other calling, later is true,
//don't call again completer()
}
// _controller.complete(controller);
_googleMapController = controller;
// Set Initial Camera Position
setCameraPosition(
position: locationData.getCurrentAddress.position
as Position);
setMapBounds();
setState(() {});
},
),
The zoom is stuck on the last zoom level when setting camera position previously and I would like to rest it when I click the myLocationButton.
The setMapBounds(); method call sets the zoom which depends on map bounds and calls the code below which can result in a high zoom level and the zoom level persists after the call, when I click the myLocationButton.
_googleMapController!
.animateCamera(CameraUpdate.newLatLngBounds(latLngBounds, 70));
How can I reset the zoom level after animating the camera?
Can you please try this one if it helps.try to setState zoomValue
double zoomValue=14.0;
LatLng mapCenter = new LatLng("your latitude", "your longitude");
initialCameraPosition: CameraPosition(
target: mapCenter,
zoom: zoomValue,
),
Try this
GoogleMap(
zoomGesturesEnabled: true,
tiltGesturesEnabled: false,
onCameraMove:(CameraPosition cameraPosition){
print(cameraPosition.zoom);
},
Related
I am doing a project that allows a user to upload a geojson file and add the polygons/polylines to the Google Map as a layer.
To be clear I'm using google_maps_flutter package: https://pub.dev/packages/google_maps_flutter
GoogleMap(
myLocationButtonEnabled: true,
mapType: _currentMapType,
zoomGesturesEnabled: true,
compassEnabled: true,
myLocationEnabled: true,
gestureRecognizers: Set()
..add(Factory<EagerGestureRecognizer>(
() => EagerGestureRecognizer())),
zoomControlsEnabled: true,
initialCameraPosition: cameraPosition ?? _defaultCameraPosition,
onMapCreated: (controller) {
_controllerGoogleMap.complete(controller);
_googleMapController = controller;
_determinePosition();
},
markers: _markers),
However, while trying to implement this, I did not find a clear way to implement this. What ways can I use to do this?
Any help will be appreciated. Thanks
I have set up google_maps_flutter as in the code below with zoomControlsEnabled: true and mapToolbarEnabled: true.
I want to use the Map Toolbar for assisted point-to-point navigation with Google Maps. The Tool Bar Shows up on the map when I click a marker.
I can see both the Zoom Controls and the Map Tool Bar in the Android Emulator for the Flutter app but they are not there in the iOS Simulator.
Can someone please point out what I am missing here?
Thanks
GoogleMap(
padding: EdgeInsets.only(
bottom: _mapBottomPadding,
),
mapType: MapType.normal,
initialCameraPosition: _baseLocation,
myLocationButtonEnabled: true,
myLocationEnabled: true,
zoomControlsEnabled: true,
zoomGesturesEnabled: true,
mapToolbarEnabled: true,
// minMaxZoomPreference: const MinMaxZoomPreference(12, 14),
polylines: _polylineSet,
markers: _markersSet,
onMapCreated: (GoogleMapController controller) async {
if (!_controller.isCompleted) {
//first calling is false
//call "completer()"
_controller.complete(controller);
// setState(() {});
} else {
//other calling, later is true,
//don't call again completer()
}
// _controller.complete(controller);
_googleMapController = controller;
// Set Driver Current Position
locationData.getCurrentPosition().then(
(value) {
if (mounted)
setState(() {
_driverLatitude = value.latitude;
_driverLongitude = value.longitude;
});
},
).catchError(
(error) {
showLocationPermissionsAlert(
context,
error.toString(),
);
},
);
setMapBounds();
setState(() {});
},
),
I am trying to make draggable circle in google maps in flutter but i don't know how to do that?
How can i do it in flutter?
I have the circle on google map
widget but i can't drag it
Set<Circle> circles = Set.from([Circle(
circleId: CircleId(id),
center: LatLng(latitude, longitude),
radius: 4000,
)]);
GoogleMap(
mapType: MapType.normal,
myLocationEnabled: true,
myLocationButtonEnabled: true,
initialCameraPosition: initialMapLocation,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
onCameraMove: null,
circles: circles,
);
please look at this Question and answer . for Drag and Resize a View
https://stackoverflow.com/a/63954279/6813907
i am new in flutter and i'm build a simple app with google_map_flutter package.
I understand that the first time the location button is not showed due to location permission. I would like to update the state of the location button to true once the user grant the permission. below the code.
children: [
GoogleMap(
padding: EdgeInsets.only(bottom: _bottomPaddingOfMap, top: 32),
mapType: MapType.normal,
myLocationButtonEnabled: _myLocationButtonEnabled,
initialCameraPosition: _kGooglePlex,
myLocationEnabled: true,
zoomGesturesEnabled: true,
zoomControlsEnabled: true,
onMapCreated: (GoogleMapController controller) {
_controllerGoogleMap.complete(controller);
newGoogleMapController = controller;
setState(() {
//..... update _myLocationButtonEnabled??
_bottomPaddingOfMap = 280.0;
});
locatePosition();
},
),....
I'm using a permission_handler package but not sure about how to use it. I guess I've to update the _myLocationButtonEnabled variable to true once user granted permission.
How can I do this?
Any help will be appreciated.
Thanks guys.
I am using google maps flutter plugin for my flutter mobile app. It works fine but when i take a screenshot of the map using three fingers vertical swipe across the screen (As is the gesture for all/most Redmi Phones), the map then stops responding to any gesture at all (scrolling, zooming, etc. nothing works). It stays frozen until i reload the page. I have added some gestures like
body: GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(lat,long ), zoom: 12),
myLocationEnabled: true,
tiltGesturesEnabled: true,
compassEnabled: true,
scrollGesturesEnabled: true,
zoomGesturesEnabled: true,
onMapCreated: _onMapCreated,
markers: Set<Marker>.of(markers.values),
gestureRecognizers: Set()
..add(Factory<PanGestureRecognizer>(() => PanGestureRecognizer()))
..add(Factory<ScaleGestureRecognizer>(() => ScaleGestureRecognizer()))
..add(Factory<TapGestureRecognizer>(() => TapGestureRecognizer()))
..add(Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer())
),