我在v3中升级google maps 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);
}
});
}
为什么它不起作用?有人有想法吗?
答案 0 :(得分:0)
它无法正常工作,因为无法找到路线且路线服务正在返回一个错误,该错误被忽略(或被忽略)。
我怀疑问题是你的开始和结束地址中的“@”。删除它们(以及它们之后的文本),给出路线服务有效地址(或将其作为google.maps.LatLng对象的坐标)。