Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

Google Maps Autocomplete: how to get lat/lng?

I'm using Google Maps' autocomplete feature for geocoding. It seems to return a lot of data, but not the lat/lng. Is there a way to get this information? I'd like to pass it back to my backend application for further processing.

question from:https://stackoverflow.com/questions/10957649/google-maps-autocomplete-how-to-get-lat-lng

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are methods called lat() and lng() that exist on the geometry object's prototype. So to get the values, just use the following:

var place = autocomplete.getPlace();

var lat = place.geometry.location.lat(),
    lng = place.geometry.location.lng();

// Then do whatever you want with them

console.log(lat);
console.log(lng);

console.warn('Warning: I didn't test this code!');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...