Google Maps JavaScript API v3 directions capabilities

后端 未结 1 1876
清歌不尽
清歌不尽 2021-02-06 18:28

I use Google Maps js API v3. I can show directions with waypoints based on this. What I want is getting the points of the direction. Lets say the direction line goes from Budape

相关标签:
1条回答
  • 2021-02-06 19:29

    When calling the DirectionsService.route method, pass a callback as the second parameter. The first parameter in the callback will be a DirectionsResult object. Get all the points of the directions by looping through the children of this object:

    DirectionsService.route(request, function(result, status) {
        var pointsArray = [];
    
        for (var route in result.routes) {
            for (var leg in route.legs) {
                for (var step in leg.steps) {
                    for (var latlng in step.path) {
                        pointsArray.push(latlng)
                    }
                }
            {
        }
    });
    

    In the end, pointsArray will hold all the LatLng points between the start and destination points.

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