views:

17

answers:

1

Hey guys,

I've got a html / php form which will add values to a a database. I'd like to implemented Google maps so that when a user clicks on a location on the map it will automatically add the latitude and longitude of the location which they clicked at to 2 fields on the HTML form (the Latitude and Longitude fields). How would I do this?

+1  A: 

It has been quite a while since I last played with google maps, but from what I remember...

First you need an click handler on the map. You then use the point object passed to the click handler, which contains the lng and lat as .x and .y respectively.

GEvent.addListener(myMap, 'click', function(overlay, latLng) {
    if (overlay) {
        // Code for if they clicked an overlay in the map, i.e.- a pin

    } else if (latLng) {
        lngTextbox.value = latLng.lat()
        latTextbox.value = latLng.lng()
    }
}

And yes, this is a duplicate as pointed out above (just noticed that post).

MarkD