I’m using the following function to get the elevation on Google Maps:
function getElevation(event) {
var locations = [];
var clickedLocation = event.latLng;
locations.push(clickedLocation);
var positionalRequest = {
'locations': locations
}
elevator.getElevationForLocations(positionalRequest, function(results, status) {
if(status == google.maps.ElevationStatus.OK) {
var s = results[0].elevation;
if(results[0]) {
$('#elevation').html(parseInt(s).charAt(0) + ' meter');
} else {
alert('Inget resultat hittades');
}
} else {
alert('Det gick inte att hitta höjdskillnaden på grund av följande: ' + status);
}
});
}
I’m getting Uncaught TypeError: Object 65 has no method 'charAt' when I click somewhere on the map and I don’t know how I shall fix this problem. parseInt(s) prints for example 44 depending on where you click on the map. If I click on the ocean it shows for example -4837 and it’s just that minus character I want to identify if it’s exists in this string.
Any ideas of how I can fix this problem?
Thanks in advance.
Numbers don’t have a “charAt()” method on their prototype, but strings do.
The
parseInt()function returns a number. You have to explicitly convert it to a string first.Why it is that you’re trying to make it a number in the first place is a little mysterious.