Faloude Faloude - 5 months ago 47
Javascript Question

Google maps API: get lat / long separately

After sending a

request and receiving a response with status OK, you can use
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


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();