how to draw a circle in google maps
Google Maps Flutter: Marking, circumvolve and polygon.
Today offer services that are related to location has go nigh central when it comes to mobile applications. And luckily we have Google Maps abreast us, which creates immersive location experiences and helps united states make the best business decisions with accurate data in real fourth dimension.
Fast development, expressive and flexible UI and native performance, made Flutter ane of the main and about popular tools for developing cross-platform applications. Now, we're going to talk well-nigh the use of the plug-in: google_maps_flutter and how to utilize it.
Later all you should be able to draw polygons, put a mark on map, and create a round expanse.
Then, allow's do it. Install the dependencies:
The location plugin is needed to request location, so you should e'er check manually Location Service status and Permission status. I've did it in my home.dart as the prototype below shows.
To get an API cardinal for Google Maps, you should follow the instructions in hither.
At present, create a new dart file, for this example I've created the goomap.sprint . It should expect receive the location data from the home folio.
And initialize the variables for maps' components, ids controllers and the controllers of types to describe on map.
On initState() receive the electric current location.
Marker:
To mark a single location on the map, Google Maps provides markers. These markers utilize a standard icon (that tin can be customized). It's a skilful tool to get the location ( LatLng ) in a single point, or many points on the map.
Circle:
Circles are bully when you need to make a marker on the map from a certain geometric radius, such equally a bounded area, a mark of population density, frequency of events on the map, etc.
In this example the radius value is passed in a Dialog to user select it when press the 'Circle' button on map.
Polygon
A polygon defines a series of connected coordinates in an ordered sequence. Additionally, polygons form a closed loop and define a filled region.
The list of points to describe the polygon, polygonLatLngs is fed by LatLng points received on google Maps onTap() before calling _setPolygon() .
Google Map Widget
It's time to create the GoogleMap. The map in this instance is one of the children of a Stack widget, considering it'due south going to receive a layer of buttons on it. The initialCameraPosition it's instantiated a CameraPosition object, receiving the LatLng provided by location plugin. At present you should set the markers , circles , and polygons to the map. If y'all wanna show the bluish betoken with the electric current position, fix myLocationEnabled to true.
The "magic" occurs in here: onTap() — offset is verified the option selected by the user (polygon, marking, circle) an then it's called the right function. By default I've putted _isPolygon equally true.
Layer of buttons
To cull the kind of action you wanna to practise on map, it'due south created a layer of push, that modify the bool controllers set at the start.
The beginning two options were shown higher up, which are polygon and mark. Whose only the change in bool variables is performed.
For the circle option, when selected, an AlertDialog with a TextField is returned to insert the desired radius as shown in the image beneath.
When pressed 'ok' the dialog closes and then you tin tap on map to create a new circle.
Anyway, this is an example of how to create and use the google_maps_flutter, to collect location information and improve decision making with accurate information in existent time.
I thank the readers.
Source lawmaking
Any questions contact me via LinkedIn.
Source: https://medium.com/@zeh.henrique92/google-maps-flutter-marker-circle-and-polygon-c71f4ea64498
Posted by: bentleyswuzzin.blogspot.com

0 Response to "how to draw a circle in google maps"
Post a Comment