【问题标题】:get and parse JSON with jquery from gmaps to find coordinates使用 jquery 从 gmaps 获取并解析 JSON 以查找坐标
【发布时间】:2010-05-06 08:33:03
【问题描述】:

我想解析这样的 json http://maps.google.com/maps/api/geocode/json?address=milano&sensor=false 只是为了找到一个地址的纬度和经度(在本例中是 milano)。

有人可以帮助我吗?提前非常感谢:)

【问题讨论】:

    标签: jquery json google-maps


    【解决方案1】:

    一种快速而肮脏的方式:

    $.getJSON('http://maps.google.com/maps/api/geocode/json?address=milano&sensor=false',function(data) {
        var location = data.results[0].geometry.location;
        // coordinates are location.lat and location.lng
    });
    

    这将获取第一个结果的坐标。它可能不是您正在寻找的结果,但迭代结果以找到正确的结果是微不足道的。

    【讨论】:

    • 谢谢你,但我得到一个“类型错误:表达式'数据'[null]的结果不是一个对象。”在控制台中!
    • 看来google不再支持JSONP了,所以我不知道有什么办法可以克服跨域限制。也许你应该只使用完整的谷歌地图 JS api?
    • 是的,你是对的,刚刚试过这个 $.getJSON("maps.google.com/maps/…?", function(data, textStatus){ console.log(data); });它似乎工作...... json的结构不同,你能解释一下我该如何解析这个吗?非常感谢!
    • data.Placemark[0].Point.coordinates 包含数组中的坐标。 [0] 和 [1] 似乎是纬度和经度。
    猜你喜欢
    • 1970-01-01
    • 2017-02-11
    • 2015-11-15
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 2013-02-12
    相关资源
    最近更新 更多