繁体   English   中英

GeoCoding Google地图未定义

[英]GeoCoding Google Maps Undefined

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

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

那不是不可能吗,因为我每次都能很好地看到结果[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));
        }
    });

下一行:

var geocodeCallBack = function (results, status) {

results是具有属性results, success Object {results: Array[1], status: "OK"} ,例如Object {results: Array[1], status: "OK"}因此行:

locations[addressIndex] = results[0];

必须更改为

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM