谷歌地图标记不与Javascript中的地理编码器配合使用

谷歌地图标记不与Javascript中的地理编码器配合使用,javascript,google-maps,asynchronous,google-maps-api-3,Javascript,Google Maps,Asynchronous,Google Maps Api 3,我正在使用Google Geocoder将地址转换为一个坐标,该坐标被添加到以前的坐标数组中,所有这些坐标我都想映射到Google地图上。除了我使用GeoCoder在数组中添加的值之外,所有值都被映射。有人能帮忙吗 Following is my code : coordinatesArray is the array in which I push the new value computed from my code. var geocoder = new google.maps.

我正在使用Google Geocoder将地址转换为一个坐标,该坐标被添加到以前的坐标数组中,所有这些坐标我都想映射到Google地图上。除了我使用GeoCoder在数组中添加的值之外,所有值都被映射。有人能帮忙吗

Following is my code : coordinatesArray is the array in which I push the new value computed from my code.

    var geocoder = new google.maps.Geocoder();
    var address = route.fullname;
    var latitude , longitude;
    geocoder.geocode({'address' : address}, function(results, status) {                                                 
if (status == google.maps.GeocoderStatus.OK) {    
            latitude = results[0].geometry.location.lat();
            longitude = results[0].geometry.location.lng();
            alert("Name : " + address + " : " + latitude + " : "
                                + longitude);
            coordinatesArray.push(new google.maps.LatLng(latitude,longitude));
                    }});


function initialize() {
        var mapOptions = {
            zoom : 8,
            disableDefaultUI : true,
            center : coordinatesArray[0],
            mapTypeId : google.maps.MapTypeId.TERRAIN
        };

        map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);

        var mapPath = new google.maps.Polyline({
            path : coordinatesArray,
            geodesic : true,
            strokeColor : 'green',
            strokeOpacity : 1.0,
            strokeWeight : 2
        });
        mapPath.setMap(map);
    }

有什么建议我哪里做错了吗?

发现这是一个异步调用。如何解决这个问题?代码在我看来似乎是正确的,我用一个我知道的地址尝试了它,并给出了预期的结果。您确定您指定的地点返回的地理代码正确吗?。在某些情况下,仅检查状态是不够的,还必须检查返回的内容。通常会报告返回值,例如,在该位置不可能进行地理编码。@scaisEdge我验证的结果也是正确的。我想的问题是,由于地理代码是一个异步调用,因此在显示地图时,结果坐标不会添加到数组中。你知道怎么解决吗?奇怪的是,我每天制作数百个地理代码,而且我从来没有遇到过对这些影响做出延迟响应的问题。如果这实际上是假设,为什么不在异步执行的函数体中输入display或对display函数的调用呢?基本上,如果我理解的话,添加一个标记,这样一旦你得到结果,你就可以在地图上显示出来。