pete
pete

Reputation: 21

get lon lat from a square drawn on a map or visualize a circle on map

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.

Upvotes: 1

Views: 807

Answers (2)

Marcelo
Marcelo

Reputation: 9407

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

Upvotes: 1

david strachan
david strachan

Reputation: 7228

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.

Upvotes: 1

Related Questions