谷歌地图上的地理编码地址问题

时间:2014-06-25 08:47:06

标签: javascript google-maps google-geocoder

您好我有以下地址数组

var Address= [
    { "Key": "1", "Title": "Candidate A", "Line1": "26 Dove Ave", "line2": "", "suburb": "Altona", "state": "VIC", "postcode": "3018" },
    { "Key": "2", "Title": "Candidate B", "Line1": "101 Collins Street", "line2": "", "suburb": "Melbourne", "state": "VIC", "postcode": "3000" },
    { "Key": "3", "Title": "Candidate C", "Line1": "15 Elgin St", "line2": "", "suburb": "Carlton", "state": "VIC", "postcode": "3053" },
    { "Key": "4", "Title": "Candidate D", "Line1": "435 Bridge Road", "line2": "", "suburb": "Richmond", "state": "VIC", "postcode": "3121" }
];

然后我调用地理编码器,同时循环上面的数组,如下所示

geocoder.geocode({ 'address': address[i].Line1 + " , " + address[i].suburb },

但地图上的标记不正确,例如数组中的第一个条目在地图上显示为Swallow Street,Altona VIC 3018,澳大利亚我不知道我做错了什么?我已经尝试将郊区切换到邮政编码,但结果总是一样的??!

**添加了以下代码,显示了完整的流程

geocoder.geocode({ 'address': Address[i].Line1 + " , " + Address[i].suburb },

    function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            console.log(results);
            marker = new google.maps.Marker({
                position: new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()),
                map: map
            });

            //google.maps.event.addListener(marker, 'click', (function () { // Click event for each location to show the description
            //    return function () {
            //       GetDirections(results[0].geometry.location.lat() + "," + results[0].geometry.location.lng(), address);
            //    };
            //})(marker, i));

            google.maps.event.addListener(marker, "click", function (e) {

                var latLng = e.latLng.k + "," + e.latLng.A;

                console.log(e);

                GetDirections(latLng);

            });

            markers.push(marker);
        }
        else {
            document.getElementById("text_status").value = status;
            return;
        }
    }

0 个答案:

没有答案