Reputation: 15
I'm using the [google_map_flutter] package.
When I click the marker, I don't want the screen to move to the center of the marker. Is there a way?
Upvotes: 0
Views: 831
Reputation: 11
If you want to keep show info on marker tap, then you can use GoogleMapController.showMarkerInfoWindow()
Set<Marker> _prepareMarkers(MapState state, MapCubit cubit, BuildContext context) {
return state.markers.map((marker) => Marker(
markerId: marker.markerId,
position: marker.position,
icon: marker.icon,
infoWindow: const InfoWindow(
title: 'example title',
snippet: 'example snippet',
),
consumeTapEvents: true,
onTap: () {
state.mapController?.showMarkerInfoWindow(marker.markerId);
},
)).toSet();
}
Upvotes: 1
Reputation: 93
Well, on your GoogleMap you can set a initialCameraPosition with some default target, like:
initialCameraPosition: CameraPosition(
zoom: 13,
target: LatLng(
defaultLat,
defaultLng,
),
),
Then you can get your map controller from the onMapCreated, like:
late GoogleMapController _mapController;
void onMapCreated(GoogleMapController googleMapsController) async {
_mapController = googleMapsController;
//rest of your code...
}
And use it on the onTap() method from the Marker to "lock" your camera position by keeping it with the default target. Like:
Marker(
markerId: const MarkerId('id'),
onTap: () {
_mapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
zoom: 13,
target: LatLng(
defaultLat,
defaultLng,
),
),
),
);
},
);
It's not ideal since you still may notice the camera slightly trying to move, but it stays at the locked position.
Upvotes: 0
Reputation: 181
try this
Try set
consumeTapEvents=false
as argument of Marker constructor.
Marker marker =Marker(consumeTapEvents=false)
Upvotes: 1