Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  42] [ 5]  / answers: 1 / hits: 29462  / 9 Years ago, thu, october 15, 2015, 12:00:00

I can get place Id by using This Link. But problem is this is based on location search. I want to get place_id using draggeble marker so I can't use above link. I am moving the marker on Google Map, So how I can get place_id on Map.



Through marker.getPosition() we can get the latitude and longitude. So I want to know the place_id through latitude and longitude. How can I get, please tell me



latitude=marker.getPosition().lat();               
longitude=marker.getPosition().lng();

More From » google-maps

 Answers
7

Use google.maps.Geocoder for
Reverse Geocoding as explained here: https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse



You will recieve data containing results[1].place_id.



var geocoder = new google.maps.Geocoder;

latitude=marker.getPosition().lat();
longitude=marker.getPosition().lng();
var latlng = {lat: parseFloat(latitude), lng: parseFloat(longitude)};

geocoder.geocode({'location': latlng}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1].place_id);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});

[#64727] Tuesday, October 13, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sabrina

Total Points: 92
Total Questions: 92
Total Answers: 85

Location: Palestine
Member since Thu, Feb 2, 2023
1 Year ago
;