[英]Google Maps API Save Waypoints
I'm really struggling with waypoints and I was hoping to get some help. 我真的在航路点上苦苦挣扎,希望能得到一些帮助。
My ultimate goal is to send the waypoints data to a hidden input field that I can save to my database using PHP when the user is done plotting their route. 我的最终目标是将航路点数据发送到一个隐藏的输入字段,当用户绘制完其路线后,可以使用PHP将其保存到数据库中。
I've got the following code (Javascript API V3), but the last waypoints section keeps breaking the script. 我有以下代码(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;
});
});
I'd greatly appreciate any help you can give. 非常感谢您能提供的任何帮助。
This: 这个:
var waypoints = displayer.directions.route[0].legs[0].via_waypoint;
should be: 应该:
var waypoints = displayer.getDirections().routes[0].legs[0].via_waypoints;
Please note: start and end of a route are not included inside the waypoints-array. 请注意:路线点数组中不包括路线的起点和终点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.