関数から標高値を取得するためにいくつかの問題に直面しています。私はその価値を得ることができません。誰かがそれに対する解決策を持っていれば素晴らしいでしょう。
これが私のコードです:
function getElevation(latLng) {
seaLevel = 'Error';
var locations = [];
locations.push(latLng);
//Create a LocationElevationRequest object using the array[0] value
var positionalRequest = {
'locations': locations
}
//Initiate the location request
elevationService.getElevationForLocations(positionalRequest, function(results, status) {
if (status == google.maps.ElevationStatus.OK) {
// Retrieve the first result
if (results[0]) {
var seaLvl = parseFloat(results[0].elevation.toFixed(1));
}
dropElevation(seaLvl);
}
document.getElementById("response").innerHTML = seaLevel;
});
function dropElevation(tmpLevel) {
//alert(tmpLevel); at this point the value is correct
seaLevel = tmpLevel;
}
return seaLevel; //at this point the value is always as defined above
} //End function (getElevation)
その呼び出しは次のようになります。
var seaLvl = getElevation(latLng);
私が間違っていることを教えてくれて
ありがとう