Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
74
rated 0 times [  81] [ 7]  / answers: 1 / hits: 94490  / 15 Years ago, wed, february 24, 2010, 12:00:00

I need to draw polygon using mouse and mark a particular area on Google maps. The purpose is to mark an area on Google maps and then showing hotels and attractions on that area. The user will mark the hotels on Google map while creating them so the db will have their latitude and longitudes.



How can I draw the polygon and fill it with a color as background to mark the area in Google Maps? I have read the API Manual “how to draw polygons?” basically you would need to mark multiple points and then combine them into a polygon. But I will need to do this using mouse drag, just like drawing a shape. Kindly help me out how to achieve this.


More From » google-maps

 Answers
72

you can use the Google MyMaps polygon editing tools in your appplication, maybe this will be ok for you?



see http://googlemapsapi.blogspot.com/2008/05/love-my-maps-use-its-line-and-shape.html



However if you want to implement this yourself it is basically this:



add click listener to map.



repeat:
store points that user clicks on in an array, and add a marker at this point.
if it is the first marker add click listener to it



when user clicks on first marker, parse use the array of points to build your polygon



I don't have any code to show you, but I have implemented this myself in a previous company, so it can be done :)


[#97499] Saturday, February 20, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
coby

Total Points: 27
Total Questions: 102
Total Answers: 97

Location: Honduras
Member since Wed, Jul 14, 2021
3 Years ago
coby questions
;