【问题标题】:Get City/State from Latitude/Longitude via jquery/ajax with google maps geocode?使用谷歌地图地理编码通过 jquery/ajax 从纬度/经度获取城市/州?
【发布时间】:2012-11-05 20:50:56
【问题描述】:

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

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

谢谢!

【问题讨论】:

    标签: javascript jquery google-maps google-maps-api-3


    【解决方案1】:

    这是一个名为 reverse geocoding 的过程,Google 对此有大量文档。

    一个例子是:

    $.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*/
             }
    });
    

    【讨论】:

    • 我怎样才能从数据中只得到国家?
    • 伙计,我得到了 (var i = 0; i
    • 尝试在请求 url 中传递 &result_type=locality 你会得到城市、州、国家
    猜你喜欢
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    相关资源
    最近更新 更多