Google Maps JS API - Find name of place given location (latitude/longitude)

人盡茶涼 提交于 2021-02-18 08:20:48

问题


Given a latitude/longitude, how can I get the name of the place at that location using Google Map's JS API?

The Geocoder.geocode(..) seems to be the way to go, but am not sure what's the best way to get the exact location name out of the API results.


回答1:


Use the Geocoding API for mapping locations to addresses and addresses to locations. http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding

Geocoder.geocode( { 'latLng': latLngObject }, callback);

The callback receives results and status.

The results are pretty accurate, but you'll have to rely on approximations nevertheless, as the user location can rarely be measured exactly.




回答2:


Reverse geocode is the term you are looking for:

http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-reverse.html

Example:

http://code.google.com/apis/maps/documentation/javascript/services.html#ReverseGeocoding




回答3:


http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true

is the API call. MAKE SURE THAT THERE IS NO SPACE IN THE latlng PARAMETER



来源:https://stackoverflow.com/questions/8366610/google-maps-js-api-find-name-of-place-given-location-latitude-longitude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!