I've got an application where I would like to present the end user with a google map and allow them to select an area of the map with a simple rectangular drawing tool and then have all of the locations stored in the client's database that fall in that rectangular selection area show up as points on the map...
I have a simple understanding of google maps and can get google maps to plot all the locations on the database w/o a problem... my problem comes in allowing the end user to draw the rectangle. Not sure how to implement this.
Can someone explain or link me to an example of how it's done?
Looks like this question was asked (and answered) a few months before Google posted about the new drawing tools in v3 API ...
I have to say that using the API's drawing tools gives a better user experience than @rcravens solution. Here's a very specific implementation that lets you "select" an area on the map by drawing a rectangle or polygon, and then checking to see if a marker is inside the shape: http://jsfiddle.net/JsAJA/306/.
Interesting question. I love the google maps api. Here is a jsFiddle with your solution:
http://jsfiddle.net/JsAJA/2/
You will have to query your database for points between the minimum/maximum lat and lngs. Hope this helps.
Bob
P.S. Note that this breaks the natural user experience of google maps. The map is no longer dragged when you mouse down. It needs a better user experience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With