Faloude Faloude - 21 days ago 4
Javascript Question

Google maps API: get lat / long separately

After sending a

geocode
request and receiving a response with status OK, you can use
results[0].geometry.location
to retrieve both latitude and longitude.

But how do you get the lat / long separately? I can't find the right call in the Google maps API reference

Answer

That location field is an object of type LatLng. To get the latitude, call it's lat() method. To get the longitude, call it's lng() method.

For example:

var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
Comments