Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向MapQuest JavaScript地理代码模块动态添加地址_Javascript_Geocoding_Mapquest - Fatal编程技术网

向MapQuest JavaScript地理代码模块动态添加地址

向MapQuest JavaScript地理代码模块动态添加地址,javascript,geocoding,mapquest,Javascript,Geocoding,Mapquest,我试图在JavaScript API中使用MapQuest地理编码模块来动态批处理地理编码地址: MQA.withModule('geocoder', function() { var addresses = new Array(); $.getJSON('get_marker_json.php', function( data ) { $.each(data, function(i, item) { addresses.push(s

我试图在JavaScript API中使用MapQuest地理编码模块来动态批处理地理编码地址:

MQA.withModule('geocoder', function() {

    var addresses = new Array();

    $.getJSON('get_marker_json.php', function( data ) {

        $.each(data, function(i, item) {
            addresses.push(street: item.address, city: item.city, state: item.state, postalCode: item.zip);
        });

    });

    /*Pass an array of locations to be geocoded and placed on map*/
    map.geocodeAndAddLocations(

        // add addresses from array here
        addresses

    );

});
然而,这不起作用。似乎地址必须是预定义的。例如:

map.geocodeAndAddLocations([
            'Littleton CO',
            { city: 'Steamboat Springs', state: 'CO' },
            { street: '555 17th St', postalCode: '80202' },
            'Winter Park CO'
        ]);
我怎样才能做到这一点

谢谢

调用
getJSON()
是异步的,这意味着
map.geocodeandddlocations()
正在运行,而网络请求仍在执行,并且
地址
为空


组装
地址
数组后,将对
map.geocodeandddlocations()的调用移动到
getJSON()中的回调中。(另外,为什么要组装JSON字符串数组?

您还可以通过预先添加以下内容使getJSON()调用同步,并使其等待数组填充完成:

$.ajaxSetup({'async': false});

谢谢!你说得对,我将上面的代码更正为一个对象数组。