-1

我在 v3 中升级谷歌地图 v2 时遇到一些问题。

跟随代码是v2:

function routing(target, width, lenght, name, zip, city, street) {
    if (GBrowserIsCompatible()) {
        if (counter > 0) {directions.clear()};
        counter++;
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        directionsPanel = document.getElementById("route");
        directions = new GDirections(map, directionsPanel);

        var startpoint = name+', '+zip+' '+city+', '+street

        if (target == 'messe') {
        directions.load("from: "+startpoint+"@"+width+","+lenght+" to: Messe, 50679 #T_koeln#, Deutz-Mülheimer Straße 40@50.9473327,6.98312820000001");
        };

        if (target == 'airport') {
        directions.load("from: "+startpoint+"@"+width+","+lenght+" to: Flughafen Koeln, 50679 #T_koeln#, Kennedystraße@50.8782914,7.122399800000039");
        };
    }
}

这是 v3 代码:

var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer(); 
function routing(target, width, lenght, name, zip, city, street) {
    if (counter > 0) {directionsDisplay.setMap(null)};
    counter++;

    var mapOptions = {
        zoom: #zoomfaktor_detail#,
        center: new google.maps.LatLng(width, length), 
        overviewMapControl: true,
        overviewMapControlOptions:{opened:true},
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map"),mapOptions);
    directionsDisplay.setMap(map);

    directionsDisplay.setPanel(document.getElementById("route"));
    var startpoint = name+', '+zip+' '+city+', '+street

    if (target == 'messe') {
        end = 'Messe, 50679 #T_koeln#, Deutz-Mülheimer Straße 40@50.9473327,6.98312820000001';
        start = startpoint+"@"+width+","+lenght;
        request = {
            origin: start,
            destination: end,
            travelMode: google.maps.TravelMode.DRIVING
        };
    }
    if (target == 'airport') {
        end = 'Flughafen Koeln, 50679 #T_koeln#, Kennedystraße@50.8782914,7.122399800000039';
        start = startpoint+"@"+width+","+lenght;
        request = {
            origin: start,
            destination: end,
            travelMode: google.maps.TravelMode.DRIVING
        };
    }
    directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
        }
    });
}

为什么它不起作用?有人有想法吗?

4

1 回答 1

0

它不起作用,因为找不到路线并且路线服务正在返回一个错误,该错误(或曾经)被静默忽略。

我怀疑问题出在您的起始地址和结束地址中的“@”。删除它们(以及它们后面的文本),为路线服务提供有效地址(或将坐标作为 google.maps.LatLng 对象提供)。

于 2013-10-28T16:17:15.453 回答