【发布时间】:2016-10-16 02:45:12
【问题描述】:
我正在使用 Google Maps API 使用给定点创建方向。
我需要将点数排序为 1,2,3...99(已完成)。
点也必须是可拖动的。
但是当我使点可拖动时,方向不会自行刷新,点的位置会改变但方向不会改变,
这里是示例代码(取自 --> Google Maps Directions using 1-2-3 instead of A-B-C);
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("maps", "3",{other_params:"sensor=false"});
function init(){
directionsService = new google.maps.DirectionsService();
var pos = new google.maps.LatLng(41.218624, -73.748358);
var myOptions = {
zoom: 15,
center: pos,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), myOptions);
directionsDisplay = new google.maps.DirectionsRenderer({map: map, suppressMarkers: true,draggable:true});
directionsService.route({
origin: "New York",
destination: "Chicago",
waypoints: [{location:"Philadelphia"}, {location:"Boston"}], //other duration points
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
}, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var my_route = response.routes[0];
for (var i = 0; i < my_route.legs.length; i++) {
var marker = new google.maps.Marker({
position: my_route.legs[i].start_location,
draggable:true,
label: ""+(i+1),
map: map
});
}
var marker = new google.maps.Marker({
position: my_route.legs[i-1].end_location,
draggable:true,
label: ""+(i+1),
map: map
});
} else {
vts.alertDialog( window.localization.error,
window.localization.error_direction_calculate + ": " + status,
BootstrapDialog.TYPE_DANGER);
}
});
}
</script>
<body style="margin:0px; padding:0px;" onload="init()">
<div id="map" style="height:400px; width:500px;"></div>
</body>
这是屏幕截图;
这就是问题所在;
问题是,我必须同时使用标记和可拖动属性。
提前致谢
【问题讨论】:
-
我无法将市场与 onDrag 联系起来,也找不到任何 API 来执行此操作。你有什么想法吗?谢谢。
标签: javascript google-maps google-maps-api-3