我使用坐标数组创建了一条折线,其代码改编自 https://google-developers.appspot.com/maps/documentation/javascript/examples/polyline-simple
虽然第一种(可能也是最糟糕的)制作这条线的方法只是一个巨大的纬度/经度点列表。还在学习编程技巧,我很抱歉。我是地理学家而不是程序员!
我想从那条线上获取高程并创建一个高程剖面图。我是 JS 新手,不知道如何调试不起作用的东西。我似乎无法使用折线中的坐标填充路径数组。
它当前设置为将 bikeCourseCoordinates 推送到一个新数组,然后将其用作路径。我尝试使用 bikeCourseCoordinates 数组作为“路径”,但这也不起作用。
在线(但不是工作版本)在这里: http ://geography.uoregon.edu:50000/bentesting/map_try3.html
function drawPath() {
// Create a new chart in the elevation_chart DIV.
chart = new google.visualization.ColumnChart(document.getElementById('elevation_chart'));
var path = new Array;
path.push(bikeCourseCoordinates);
// Create a PathElevationRequest object using this array.
var pathRequest = {
'path': path,
'samples': 256
}
// Initiate the path request.
elevator.getElevationAlongPath(pathRequest, plotElevation);
}
// Takes an array of ElevationResult objects, draws the path on the map
// and plots the elevation profile on a Visualization API ColumnChart.
function plotElevation(results, status) {
if (status == google.maps.ElevationStatus.OK) {
elevations = results;
// Extract the elevation samples from the returned results
// and store them in an array of LatLngs.
var elevationPath = [];
for (var i = 0; i < results.length; i++) {
elevationPath.push(elevations[i].location);
}
// Extract the data from which to populate the chart.
// Because the samples are equidistant, the 'Sample'
// column here does double duty as distance along the
// X axis.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Sample');
data.addColumn('number', 'Elevation');
for (var i = 0; i < results.length; i++) {
data.addRow(['', elevations[i].elevation]);
}
// Draw the chart using the data within its DIV.
document.getElementById('elevation_chart').style.display = 'block';
chart.draw(data, {
width: 640,
height: 200,
legend: 'none',
titleY: 'Elevation (m)'
});
}
}