javascript 使用谷歌地图地理编码通过 jquery/ajax 从纬度/经度获取城市/州?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13428284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:44:42  来源:igfitidea点击:

Get City/State from Latitude/Longitude via jquery/ajax with google maps geocode?

javascriptjquerygoogle-mapsgoogle-maps-api-3

提问by Mark

I've seen a few jscript/jquery implementations of this concept in reverse, where you can enter a zip code and get a long/lat from the google maps api.

我已经看到了这个概念的一些 jscript/jquery 反向实现,您可以在其中输入邮政编码并从 google maps api 获取 long/lat。

However, in my case, I already have a set of coordinates and was wondering if its possible to dynamically get a textual City, State result from the API when we feed it the long/latitude via jquery?

但是,就我而言,我已经有了一组坐标,并且想知道当我们通过 jquery 为它提供经度/纬度时是否可以从 API 动态获取文本城市、状态结果?

Thanks!

谢谢!

回答by kieran

This is a process called reverse geocoding, and Google have quite extensive documentation on it.

这是一个称为反向地理编码的过程,谷歌有关于它的大量文档。

An example would be:

一个例子是:

$.ajax({ url:'http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true',
         success: function(data){
             alert(data.results[0].formatted_address);
             /*or you could iterate the components for only the city and state*/
         }
});