如何通过API访问Google自行车行驶方向的海拔高度数据?

时间:2019-05-22 19:25:51

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

我正在开发一个从自行车路线生成高程剖面的应用程序。该路线由google maps api生成,作为经纬度对的列表。

通过将此lat-lng对路径传递到Google的海拔高度api而提供的海拔数据通常与google maps本身在其海拔轮廓特征中显示的内容相同,但有时海拔数据却大不相同。特别是,当路线包含桥梁时,通过Google的海拔API访问的海拔数据会大不相同。海拔高度api似乎返回给定经纬度的“自然景观”海拔高度,而不是该特定位置处道路的海拔高度。

很明显,google具有道路高程数据,因为它们将其显示在google地图的高程配置文件中。有没有办法通过api访问此道路高程数据?

这个问题是相关的,但是没有针对这个特定问题的答案: Google Maps API 3 - JavaScript: Cycling-How to find elevation along the route?

下面的代码获取“自然景观”高程数据,而不是实际路线高程数据。是否有其他API调用可以获取我需要的数据?

// make a route request to get bicycling directions 
var request = {
        origin: new google.maps.LatLng(49.3040568,-123.1452437);
        destination: new google.maps.LatLng(49.3204922,-123.1335115);
        travelMode: google.maps.TravelMode.BICYCLING
    };
this.directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        // get elevation for the route
        var path = response.overview_path;
        var elevationRequest = {
            'path': path,
            'samples': 256
        };
        var elevationService = new google.maps.ElevationService();
        elevationService.getElevationAlongPath(elevationRequest,
            function(results, status) { 
                if(status == google.maps.ElevationStatus.OK) {
                    console.log(results);
                }
            }
        ); 
    }
});

此路径的海拔数据与google地图上显示的海拔概况完全不同: https://www.google.ca/maps/dir/49.3040568,-123.1452437/49.3204922,-123.1335115/data=!3m1!4b1!4m2!4m1!3e1

0 个答案:

没有答案