0

I need to retrieve google place data (e.g. place_id) for a specific location (point-of-interest), based on a user clicking on that location on the map.

I have tried adding a click-handler to the map object in order to get the co-ords of a user click - however, this is not called if the user clicks on a point-of-interest (there are similar, but not the same, SO questions around this - but none with a satisfactory answer).

I can't see anything in the maps / places APIs that does this - but it seems like a fairly basic requirement to me, so maybe I'm just missing something?

Thanks in advance,

Neil.

Neil
  • 1,821
  • 4
  • 14
  • 27

1 Answers1

0

Try this: http://jsfiddle.net/lotusgodkk/x8dSP/3584/

google.maps.event.addListener(map, "click", function (event) {
    var lat = event.latLng.lat(); //Get latitude from point of click
    var lng = event.latLng.lng(); // Get longitude from point of click
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({
        'latLng': new google.maps.LatLng(lat, lng)
    }, function (results, status) {
        alert(results[0].formatted_address); //Final address from lat and lng
    });
});

See the demo for more code.

You can get latitude longitude and place name as well. Is this what you need?

K K
  • 17,794
  • 4
  • 30
  • 39
  • No, unfortunately this doesn't help. As I said in my original question, the click handler on the map *does not* fire when the user clicks on a point-of-interest (something on the map already marked with an icon). Thanks anyway. – Neil Jul 04 '14 at 23:01