Javascript 谷歌地图中的航路点代码
我使用html表单获取3个邮政编码(PortZip、ImporterZip、ExporterZip)的输入 航路点公式正确吗?此代码不会导致任何结果。如果我在没有Javascript 谷歌地图中的航路点代码,javascript,google-maps,Javascript,Google Maps,我使用html表单获取3个邮政编码(PortZip、ImporterZip、ExporterZip)的输入 航路点公式正确吗?此代码不会导致任何结果。如果我在没有航路点的情况下运行代码:航路点,它会工作。我的代码怎么了?A是一个javascript匿名对象,directions请求的waypoints属性应该是一个waypoint对象数组(就像您在应用程序中使用的那样)。如果运行该代码,将出现一个javascript错误:Uncaught InvalidValueError:在属性航路点中:不是
航路点的情况下运行代码:航路点
,它会工作。我的代码怎么了?A是一个javascript匿名对象,directions请求的waypoints
属性应该是一个waypoint对象数组(就像您在应用程序中使用的那样)。如果运行该代码,将出现一个javascript错误:Uncaught InvalidValueError:在属性航路点中:不是数组
function calcRoute() {
var start = document.getElementById('PortZip').value;
var end = document.getElementById('ImporterZip').value;
var waypts = [{location:document.getElementById('ExporterZip').value}];;
var request = {
origin:start,
destination:end,
waypoints:waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
代码片段:
var映射;
var directionsService=new google.maps.directionsService();
var directionsDisplay=new google.maps.DirectionsRenderer();
函数初始化(){
//将MAP DIV转换为功能齐全的GOOGLE地图
变量映射选项={
缩放:8,
中心:新google.maps.LatLng(-34.397150.644),
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“map_canvas”),mapOptions);
方向显示.setMap(地图);
}
函数calcRoute(){
var start=document.getElementById('PortZip')。值;
var end=document.getElementById('ImporterZip').value;
var waypts=[{
位置:document.getElementById('ExporterZip')。值
}];;
var请求={
来源:start,
目的地:完,
航路点:航路点,
航路点:对,
travelMode:google.maps.travelMode.DRIVING
};
路由(请求、功能(响应、状态){
if(status==google.maps.directionstatus.OK){
方向显示。设置方向(响应);
}
});
}
google.maps.event.addDomListener(窗口“加载”,初始化)代码>
html,
身体,
#地图画布{
高度:500px;
宽度:500px;
边际:0px;
填充:0px
}
计算路线外距离。
输入5位有效的美国邮政编码
端口ZipCode:
导入器ZipCode:
导出器ZipCode:
function calcRoute() {
var start = document.getElementById('PortZip').value;
var end = document.getElementById('ImporterZip').value;
var waypts = document.getElementById('ExporterZip').value;
var request = {
origin:start,
destination:end,
waypoints:waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function calcRoute() {
var start = document.getElementById('PortZip').value;
var end = document.getElementById('ImporterZip').value;
var waypts = [{location:document.getElementById('ExporterZip').value}];;
var request = {
origin:start,
destination:end,
waypoints:waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}