How to add GeoJson file to Google Maps Flutter as a layer - flutter

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

Related

How to change moving location icon using google maps in flutter

please help me I am new in the flutter
GoogleMap(
padding: EdgeInsets.only(
top: mapBottomPadding,
),
initialCameraPosition: _kGoogle,
mapToolbarEnabled: true,
buildingsEnabled: true,
myLocationButtonEnabled: true,
myLocationEnabled: true,
mapType: MapType.terrain,
markers: markers,
trafficEnabled: true,
// on below line setting compass enabled.
compassEnabled: true,
onMapCreated: onMapcreated,
zoomControlsEnabled: true,
),
i also shared my google maps code
You can use this code snippet for google maps change moving location iconhttps://gist.github.com/samuchakraborty/243842a1a93956e64dc8781d0f9fb313

How to make a generic class for Google & Huawei maps in flutter?

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.

How to make draggable circle google map in flutter

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

How to Set Zoom Level For google_maps_flutter

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);
},

Flutter google_maps_flutter not show location button even if myLocationButtonEnabled is set to true

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.