我正在使用gmaps和JQuery。我想在地图中显示从A点到B点的方向,然后到C点。我正在使用此代码,但它不起作用:
<script type="text/javascript">
var map;
$(document).ready(function(){
map = new GMaps({
div: '#map',
lat: -12.043333,
lng: -77.028333
});
map.drawRoute({
origin: [-12.044012922866312, -77.02470665341184],
destination: [-12.090814532191756, -77.02271108990476],
destination: [-12.044012922866312, -77.02470665341184],
travelMode: 'driving',
strokeColor: '#131540',
strokeOpacity: 0.6,
strokeWeight: 6
});
});
</script>
答案 0 :(得分:2)
您传递到map.drawRoute()
函数的对象文字具有重复两次的destination
属性。 JavaScript对象只能有一个具有相同名称的属性,因此第二个destination
会覆盖第一个。
documentation for .drawRoute()
表示您应该使用waypoints
数组作为中间航点。虽然我没有测试过,但我怀疑你想要的代码看起来像这样:
map.drawRoute({
origin: [-12.044012922866312, -77.02470665341184],
waypoints: [
{
location: new google.maps.LatLng(
-12.090814532191756,
-77.02271108990476
),
stopover: true
}
],
destination: [-12.044012922866312, -77.02470665341184],
travelMode: 'driving',
strokeColor: '#131540',
strokeOpacity: 0.6,
strokeWeight: 6
});