๐ก Home ๐ Chapter ๐ Prev ๐ Next
โกย GMapsBook.com is crafted by Jozef Sorocin (๐ขย Book a consulting hour) and powered by:
Once youโve grasped the concepts behind Dragging & Editing, you can delight your users by letting them draw on your Google map.
Drawing on the map canvas enables a variety of use cases. Your users may want to:
As a matter of fact, being able to draw as part of an advanced search is one of the top community feature requests at Airbnb:
Original tweet link
Now, implementing user-friendly map drawing capabilities is daunting but not impossible.
In this chapter youโll learn how to A) work with Google Mapsโ Drawing Library and B) implement a custom, self-closing, freehand drawing tool.
To use Googleโs Drawing Library (i.e. the google.maps.drawing.DrawingManager
class), youโll first need to load this library as part of your initialization script:
< script async defer
src=".../maps/api/js?key=YOUR_KEY_STARTING_WITH_AIza&libraries=drawing&callback=initMap">
</script>
From there, you can create a DrawingManager
instance thatโll look like this by default:
The default MARKER
, CIRCLE
, POLYGON
, POLYLINE
, and RECTANGLE
drawing modes.