【问题标题】:Need to get waypoint_order after optimizedwaypoint优化waypoint后需要获取waypoint_order
【发布时间】:2015-07-07 15:56:25
【问题描述】:
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
    <script type="text/javascript">
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var something;

var locations = <?php echo json_encode($googlemaparray);?>;
var uniquelocations= <?php echo json_encode($uniquegoogle);?>;
var barinfo = <?php echo json_encode($barinfoarray);?>;
var marker, i;
var total = uniquelocations.length;
var test;

function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    map = new google.maps.Map(document.getElementById('map-canvas'), {
    zoom: 17,
    center: new google.maps.LatLng(locations[0],locations[1]),
    mapTypeId: google.maps.MapTypeId.ROADMAP
});


directionsDisplay.setMap(map);

var start = new google.maps.LatLng(uniquelocations[0],uniquelocations[1]);
var end = new google.maps.LatLng(uniquelocations[0],uniquelocations[1]);
var waypts = [];
    for (var i = 2; i < uniquelocations.length; i+=2){
        waypts.push({
        location:new google.maps.LatLng(uniquelocations[i],uniquelocations[i+1])});
    };
var request = {
    origin: start,
    destination: end,
    waypoints:waypts,
    optimizeWaypoints:true,
    travelMode: google.maps.DirectionsTravelMode.WALKING
};
directionsService.route(request, function (response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
        var something=response.routes.waypoint_order;
        console.log(something);
    }   
});
//  test = google.maps.geometry.spherical.computeDistanceBetween({
//  from:new google.maps.LatLng(uniquelocations[0],uniquelocations[1]),
//  to:new google.maps.LatLng(uniquelocations[2],uniquelocations[3])
//  });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>

我如何从 waypoint_order 获得对数组的访问权限,因为我需要知道我的航点是如何排序的。当我对现有代码进行 console.log(something) 时,它在控制台中显示“未定义”。我正在使用 WAMP 堆栈来测试此代码。

感谢您的帮助。

【问题讨论】:

标签: javascript php google-maps-api-3


【解决方案1】:

航点顺序为response.routes[0].waypoint_order(如果返回多条路线,则0 是第一条路线)。

【讨论】:

    猜你喜欢
    • 2010-09-24
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 2017-04-02
    • 2014-02-15
    • 2021-04-01
    • 1970-01-01
    相关资源
    最近更新 更多