1

does anyone know if it is possible to draw a square on a (google) map and have the Topleft and Bottomright corners of this square pre-populate 4 form-fields outside of the map with their respective longtitude & lattitude

Alternative :

If the above is not feasible, is it possible to have a user click on a map and pull away from this coordinate creating a circle with increasing radius ?

In both options the square or circle needs to be visualized on screen (map overlay ?).

Looking for a simple and clean solutions for a user to select a region on a map so a database can be probed based on lat-lon data.

pete
  • 21
  • 4
  • Hope this question from stack overflow itself help you http://stackoverflow.com/questions/7976196/box-rectangle-draw-selection-in-google-maps – arjuncc Oct 28 '12 at 13:34
  • http://yogeshmprajapati.blogspot.in/2012/04/google-maps-create-marker-and-draw-line.html – arjuncc Oct 28 '12 at 13:36
  • @marcelo I have tried http://downloadbedrijven.nl/geografische-selectie.php which works and does the job, but is very ugly, not user friendly and code is jumble of javascript interlaced with php. – pete Oct 30 '12 at 21:37

2 Answers2

1

Google Maps JavaScript API V3 allow map objects to store state and update their presentation automatically by implementing MVC objects.

Two of these may interest you in your project.

These are Rectangle overlay and Circle overlay

These 2 SAMPLES Rectangle and Circle use these overlays which you can be used as a basis for your project.

The coordinates below can then be used to search database.(Using AJAX)

var latLngBounds = new google.maps.LatLngBounds(
      marker1.getPosition(),
      marker2.getPosition()
    );

The SQL query should look like this

SELECT * FROM table WHERE lat BETWEEN lat1 AND lat2  AND lng BETWEEN  lon1 AND lon2

You should also think about using PDO with prepared statements.

david strachan
  • 7,174
  • 2
  • 23
  • 33
  • Oohh.. that's looking good. feel like I am halfway there. I already built a crazy contraption [here] (http://downloadbedrijven.nl/geografische-selectie.php), but if I could somehow get the 4 coordinates (lat,lon | lat,lon) on the two corners in 4 form fields we'd have a winner. Any suggestions to tie that into the rectangle overlay sample above ? – pete Oct 30 '12 at 21:33
  • I ran your demo and viewed source. As you have topleft and bottom right you can use them for other corners ` topright "51.97800031536022 5.39056758918241"//lat of top &lng of bottom bottomleft 51.75263294955848 5.1345982838458895" //lat ofbottom &lng of top`. I hope you can understand this. – david strachan Oct 30 '12 at 21:52
  • I do understand what you are saying, but only need 2 opposite corners - each with their respective lat/lon data - creating 4 datapoints. (It matters not which opposing corners they are). I am just looking for the user-frienliest options (which imho would be an add-on to your rectangle sample). Just trying to figure out how to extrapolate the data from your example so I can use it to query a database once user hits a 'confirm' button (form field) – pete Oct 30 '12 at 22:08
  • SQL query `SELECT * FROM table WHERE lat BETWEEN 51.97800031536022 AND 5.1345982838458895 AND lon BETWEEN 51.75263294955848 AND 5.39056758918241`. Obviously coordinates are taken from map. – david strachan Oct 30 '12 at 22:33
  • FINAL RESULT is in. David's sample pointed me in the right direction. see http://downloadbedrijven.nl/geografische-selectie.php for the working version. – pete Oct 31 '12 at 08:16
1

I've got this old demo which might do what you want, but it is made with the V2 API. You'd have to convert it to V3:

http://maps.forum.nu/gm_drag_polygon.html

Marcelo
  • 9,387
  • 3
  • 35
  • 40
  • nice demo too .. but I finished my quest right before your post came in. thx for the effort though. improvements/comments welcome: http://downloadbedrijven.nl/geografische-selectie.php – pete Oct 31 '12 at 08:20