【问题标题】:Google Geocode AJAX - Lookup by Zip Code invalid but returning dataGoogle Geocode AJAX - 按邮政编码查找无效但返回数据
【发布时间】:2017-10-23 23:45:52
【问题描述】:

我正在尝试使用 url 查询 Google Geocode API

http://maps.google.com/maps/api/geocode/json?address=00000

我期待类似的结果,并在我的浏览器和 SoapUI 等 3rd 方工具中收到此结果。

{
 "results" : [],
 "status" : "ZERO_RESULTS"
}

但是,当我使用 JQuery 和 Ajax 查询地址时...

            var googleAPI = "http://maps.google.com/maps/api/geocode/json?";
            var addressCombined = "address=" + jQuery('#ZipCode').val();

            alert(addressCombined);
            $.getJSON(googleAPI,
                {
                    address: addressCombined
                })
                .done(function(data) {
                    alert(googleAPI + addressCombined);
                    alert(JSON.stringify(data));
                   }
                .fail(function(error) {
                    alert("no");
                    console.log("ERROR");
                    console.log(error);
                });

我在罗德岛找了一个地方。知道为什么吗? 这是一些截图

【问题讨论】:

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


    【解决方案1】:

    试试这个:

    var googleAPI = "http://maps.google.com/maps/api/geocode/json?";
    var addressCombined = jQuery('#ZipCode').val();
    
    alert(addressCombined);
    $.getJSON(googleAPI,
        {
            address: addressCombined
        })
        .done(function(data) {
            alert(googleAPI + addressCombined);
            alert(JSON.stringify(data));
           }
        .fail(function(error) {
            alert("no");
            console.log("ERROR");
            console.log(error);
        });
    

    无需在变量addressCombined 中添加address,因为我们使用参数address 在ajax 中发送它

    问题:google api url字符串http://maps.google.com/maps/api/geocode/json?&address=address=00000中有多个address应该是http://maps.google.com/maps/api/geocode/json?&address=00000

    【讨论】:

    • 当我尝试使用 JQuery/Ajax 查询时,结果相同。我还编辑了这个问题。我意识到我并不清楚我在问什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    • 2018-10-17
    相关资源
    最近更新 更多