我正在学习如何绘制路线。之所以能做到这一点,是因为这里看到的这篇出色的帖子。我认为将航点添加到此示例的简单过程如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API v3 Directions Example</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></head>
<body style="font-family: Arial; font-size: 12px;">
<div style="width: 600px;">
<div id="map" style="width: 580px; height: 300px; float: left;"></div>
</div>
<script type="text/javascript">
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var orig = new google.maps.LatLng(34.011689,-118.49633);
var dest = new google.maps.LatLng(34.040818,-118.26815);
//New coordinate defined below
var wps1 = new google.maps.LatLng(34.069654,-118.44434);
//Here is the waypoint
var waypts = [{ location: wps1, stopover: true }];
var map = new google.maps.Map(document.getElementById('map'), {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
directionsDisplay.setMap(map);
var request = {
origin: orig,
destination: dest,
waypoints: waypts, //Adding the waypoint here
travelMode: google.maps.DirectionsTravelMode.DRIVING
}
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
</script>
</body>
</html>
当我对此进行测试时,我只看到一条从海滩到洛杉矶市中心的非常直接的路线。我试图让它先显示绕道去加州大学洛杉矶分校。
我已经查看了一些 Google文档,但就我而言。我上面所做的应该有效吗?我知道,计算机不会撒谎,但不管它是什么,都必须是微妙的。
1. 我以正确的格式添加了航点。 2. 我告诉请求处理那个航路点。
出了什么问题?