Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Latitude and Longitude from Google Places search api using Javascript

How do I get the longitude and latitude from the searched location with the google maps place search box api.

Im using the same code as the google demo - https://developers.google.com/maps/documentation/javascript/examples/places-searchbox

like image 936
Programit Avatar asked Jan 04 '14 02:01

Programit


People also ask

How do I get data from Google Maps places API?

Go to APIs & Services → Dashboard → Enable APIs & Services at the top and Choose Maps Javascript API from the API Library. This will open up the Map JavaScript API page, and Enable it.

How do I find the latitude and longitude of a place id?

From the place_id you got, query Place Details something like https://maps.googleapis.com/maps/api/place/details/json?placeid={placeid}&key={key} and you can get the lat and lng from result.


1 Answers

function GetLatlong() {   var geocoder = new google.maps.Geocoder();   var address = document.getElementById('textboxid').value;    geocoder.geocode({     'address': address   }, function(results, status) {      if (status == google.maps.GeocoderStatus.OK) {       var latitude = results[0].geometry.location.lat();       var longitude = results[0].geometry.location.lng();     }   }); } 

You can use the above function which will give you the latitude and longitude for the area entered by user.

like image 93
Piyush Sahu Avatar answered Oct 02 '22 10:10

Piyush Sahu