How to get the list of waypoints of a route displayed on the Google maps, through their API V3?

后端 未结 3 1463
难免孤独
难免孤独 2021-02-06 13:37

The GDirections class of Google maps API helped me in \"displaying\" the route between two supplied coordinates.

Now I want a list of ALL

相关标签:
3条回答
  • 2021-02-06 14:11

    Solved this myself :) The overview_path was the correct method w.r.t displaying the coordinates: Just for checking if this really shows something, I have displayed markers on the resulting first four coordinates.

    directionsService.route (request, 
                                function (result, status) 
                                {
                                    alert(status);
                                    if (status == google.maps.DirectionsStatus.OK)
                                    {
                                        directionsDisplay.setDirections (result);
    
                                        var pointsArray = [];
    
                                        pointsArray = result.routes[0].overview_path;
    
                                        var point1 = new google.maps.Marker ({
                                            position:pointsArray[0],
                                            draggable:true,
                                            map:map,
                                            flat:true
                                            });
    
                                        var point2 = new google.maps.Marker ({
                                            position:pointsArray[1],
                                            draggable:true,
                                            map:map,
                                            flat:true
                                            });
    
                                        var point3 = new google.maps.Marker ({
                                            position:pointsArray[2],
                                            draggable:true,
                                            map:map,
                                            flat:true
                                            });
    
                                        var point4 = new google.maps.Marker ({
                                            position:pointsArray[3],
                                            draggable:true,
                                            map:map,
                                            flat:true
                                            });
    
    0 讨论(0)
  • 2021-02-06 14:14

    The overview_path doc says it returns

    An array of LatLngs representing the entire course of this route. The path is simplified in order to make it suitable in contexts where a small number of vertices is required.

    I don't interpret that to mean the same thing as returning an array of all the waypoints on a route. And in your question, it's not clear to me whether you want waypoints or coordinates (lat long) or both. If I were you, I'd also consider legs, which returns

    an array of DirectionsLegs, each of which contains information about the steps of which it is composed. There will be one leg for each waypoint or destination specified.

    Within DirectionsLeg, I think you should also take a look at steps and via_waypoints.

    0 讨论(0)
  • 2021-02-06 14:25

    Try http://vikku.info/programming/google-maps-v3/draggable-directions/saving-draggable-directions-saving-waypoints-google-directions-google-maps-v3.htm

    or Google Maps JavaScript API v3 directions capabilities

    0 讨论(0)
提交回复
热议问题