I am trying to get elevation data on click in google maps api. for that following is what I have implemented.
function getElevationtimeer(lat, lng) {
returnvaluetime = "";
elevationpoint = "";
getElevation(lat, lng);
setTimeout(ajax, 3000);
return returnvaluetime;
}
function getElevation(lat, lng) {
var locations = [];
elevator = new google.maps.ElevationService();
var clickedLocation = new google.maps.LatLng(lat, lng);
locations.push(clickedLocation);
var positionalRequest = {
'locations': locations
}
elevator.getElevationForLocations(positionalRequest, function (results, status) {
if (status == google.maps.ElevationStatus.OK) {
if (results[0]) {
elevationpoint = results[0].elevation;
} else {
}
} else {
}
})
return returnvaluetime;
}
function ajax() {
if (elevationpoint != "")
returnvaluetime = elevationpoint;
}
Initially I am calling getElevationtimeer
method.
From that I am calling first getElevation
method, in which I am finding elevation for clicked location.
After that I am calling ajax
method, in which I am assigning elevation value to the variable which I want to return from main method.
I can understand what is going wrong in above code. Please help me what is possible way to implement the logic for getting elevation.