我请求获取给定lat,long的高程配置文件。我使用了下面的代码。然而,这段代码给出了错误的输出。我已经将其与google地图在线结果进行了比较。
function elevationVal(event)
{
var lat = xval passed ;
var lng = yval passed ;
var altitudes = [];
var locations = [];
var latlng1 = new google.maps.LatLng(lat,lng);
locations.push(latlng1);
var positionalRequest = {
'locations': locations
}
elevator = new google.maps.ElevationService();
elevator.getElevationForLocations(positionalRequest, function(results, status) {
var seaLvl = results[0].elevation;
eval01.setValue(seaLvl);
if (status == google.maps.ElevationStatus.OK) {
// Retrieve the first result
if (results[0]) {
var seaLvl = altitudes.push(results[0].elevation.toFixed(3));
var eleval= results[0].elevation;
}
else {
alert("No results found");
}
} else {
alert("Elevation SERVICE FAILED due to: " + status);
}
});
}seaLvl或eleval都不能提供正确的高程值。如果有人开发了没有地图的代码,请帮助我。
谢谢,RB
发布于 2014-10-01 07:46:54
我做了一个jsfiddle来试一下,它工作得很好:http://jsfiddle.net/OxyDesign/0sgoqqco/
结果和Google Demo中的结果一样好:https://developers.google.com/maps/documentation/javascript/examples/elevation-simple
$(document).ready(function(){
$('#button').on('click',function(){
var elevator = new google.maps.ElevationService(),
denali = new google.maps.LatLng($('[name=lat]').val(), $('[name=lng]').val()),
positionalRequest = {'locations':[denali]};
elevator.getElevationForLocations(positionalRequest, function(results, status) {
if (status == google.maps.ElevationStatus.OK) {
if (results[0]) {
$('#result').text(results[0].elevation);
} else {
alert("No results found");
}
} else {
alert("Elevation service failed due to: " + status);
}
});
});
});而且我也没有做地图
也许我没弄明白问题所在
https://stackoverflow.com/questions/26129014
复制相似问题