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
Related
I am using Google maps in my flutter application and needed to integrate Huawei maps too. So every code related to the maps now is duplicated like:
Map<MarkerId, Marker> googleMarkers = <MarkerId, Marker>{};
Map<huawei.MarkerId, huawei.Marker> huaweiMarkers = <huawei.MarkerId, huawei.Marker>{};
void _onHuaweiMapCreated(huawei.HuaweiMapController controller) =>
_huaweiMapController = controller;
void _onGoogleMapCreated(GoogleMapController controller) => _googleMapController = controller;
GooglePlayServicesHelper.googlePlayServicesAvailable
? GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(30.0, 40.0),
zoom: 11.0,
),
onMapCreated: _onGoogleMapCreated,
myLocationButtonEnabled: false,
zoomControlsEnabled: false,
markers: Set<Marker>.of(googleMarkers.values),
)
: huawei.HuaweiMap(
initialCameraPosition: huawei.CameraPosition(
target: huawei.LatLng(30.0, 40.0),
zoom: 11.0,
),
onMapCreated: _onHuaweiMapCreated,
myLocationButtonEnabled: false,
zoomControlsEnabled: false,
markers: Set<huawei.Marker>.of(huaweiMarkers.values),
),
and so on...
My question is if there is any way I can use generic or abstract classes (interface concept) instead of all these conditions and duplicated code? Especially if I wanted to integrate another type of maps in the future in order to achieve open-closed principle.
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 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);
},
I can show Google Map on my Flutter app by using the code below
final marker = Marker(
markerId: MarkerId("someID"),
position: LatLng(0.0, 0.0),
infoWindow: InfoWindow(title: "Venue Name"),
);
GoogleMap(
onTap: (newCoordinate) => onMapTapped(newCoordinate, controller),
mapType: MapType.normal,
onMapCreated: onGoogleMapCreated,
initialCameraPosition: CameraPosition(
target: LatLng(0.0, 0,0),
zoom: 15.0,
),
markers: {marker},
),
to show the info window, I need to tap that red marker first. what I want is ....
whenever the map load in the screen, that info window will immediately open without I need to tap the red marker. so I can show that "Venue Name" . how to do that?
Thanks to Nelson Jr to give a clue, I can solve it by using this code showMarkerInfoWindow method from Google Map Controller. please see the onMapCreated property below
GoogleMap(
onTap: (newCoordinate) {},
onMapCreated: (mapController) {
mapController.showMarkerInfoWindow(MarkerId("yourMarkerIdHere"));
},
mapType: MapType.normal,
myLocationButtonEnabled: false,
initialCameraPosition: CameraPosition(
target: LatLng(0.0, 0.0),
zoom: 15.0,
),
),
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())
),