【问题标题】:GeoCoding Google Maps Undefined地理编码谷歌地图未定义
【发布时间】:2014-03-16 03:59:20
【问题描述】:

在下面的代码中,当我停止 FireBug 中的代码时,“结果”对象是一个很好的数组,其中填充了 良好的地理编码值

但是,我放入的 locations[] 数组中充满了所有“undefined”值。

这难道不是不可能的,因为我每次都能看到 results[0] 运行良好吗?

 var locations = [];

    function makeCallback(addressIndex) {
        var geocodeCallBack = function (results, status) {
            if (status == "success") {
                locations[addressIndex] = results[0];
            }
        };
        return geocodeCallBack;
    }

    $(function() {
        for (var x = 0; x < addresses.length; x++) {
            $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' + addresses[x], null, makeCallback(x));
        }
    });

【问题讨论】:

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


    【解决方案1】:

    行后:

    var geocodeCallBack = function (results, status) {
    

    results 是具有属性results, success 的对象,例如Object {results: Array[1], status: "OK"} 所以行:

    locations[addressIndex] = results[0];
    

    必须改成

    locations[addressIndex] = results.results[0];
    

    【讨论】:

      猜你喜欢
      • 2016-07-25
      • 1970-01-01
      • 2014-04-15
      • 2017-06-22
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      相关资源
      最近更新 更多