[英]Google Maps API Save Waypoints
我真的在航路點上苦苦掙扎,希望能得到一些幫助。
我的最終目標是將航路點數據發送到一個隱藏的輸入字段,當用戶繪制完其路線后,可以使用PHP將其保存到數據庫中。
我有以下代碼(Javascript API V3),但是最后的路標部分一直在破壞腳本。
jQuery(document).ready(function(){
// INITIALIZE MAP
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 5,
center: new google.maps.LatLng(37.09024, -95.71289),
mapTypeId: google.maps.MapTypeId.ROADMAP
}),
directions = new google.maps.DirectionsService(),
displayer = new google.maps.DirectionsRenderer({
draggable: true
});
// LOAD DEFAULTS
/* start coordinates */
var start_lat = jQuery('input[name="origin_lat"]').val();
var start_lng = jQuery('input[name="origin_lng"]').val();
/* end coordinates */
var end_lat = jQuery('input[name="destination_lat"]').val();
var end_lng = jQuery('input[name="destination_lng"]').val();
displayer.setMap(map);
directions.route({
origin: new google.maps.LatLng(start_lat,start_lng),
destination: new google.maps.LatLng(end_lat,end_lng),
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function (result) {
displayer.setDirections(result);
});
// INFO WINDOW AND MARKERS
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map
});
// WAYPOINTS
google.maps.event.addListener(displayer, 'directions_changed', function(){
var waypoints = displayer.directions.route[0].legs[0].via_waypoint;
});
});
非常感謝您能提供的任何幫助。
這個:
var waypoints = displayer.directions.route[0].legs[0].via_waypoint;
應該:
var waypoints = displayer.getDirections().routes[0].legs[0].via_waypoints;
請注意:路線點數組中不包括路線的起點和終點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.