gpt4 book ai didi

javascript - 谷歌海拔没有 map 显示

转载 作者:行者123 更新时间:2023-12-03 11:44:14 26 4
gpt4 key购买 nike

我需要获取给定纬度、经度的海拔剖面图。我使用下面的代码。然而这段代码给出了错误的输出。我已经将其与在线谷歌地图结果进行了比较。

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 都没有给出正确的海拔值。如果有人在没有 map 的情况下开发了代码,请帮助我。

谢谢,RB

最佳答案

我做了一个 jsfiddle 来尝试,它工作正常:http://jsfiddle.net/OxyDesign/0sgoqqco/

结果与 Google 演示中一样好: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);
}
});
});
});

我没有制作 map

可能是我没理解问题

关于javascript - 谷歌海拔没有 map 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26129014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com