Logic, but in a different way

Daft Logic

Google Maps Find Altitude

Last Updated 23th November 2013

Search For Location : Drop Marker?

[Map Height : Small - Medium - Large]

Output latitude,longitude? Output in meters? Output in feet?

Upload and Plot Addresses

Paste one address per line then click [Load]. There is a limit of 100 rows per batch. Any additional rows will be ignored.

Description

A method of determining altitude (height) when a point is clicked on a map.

How To Use

  1. Click on the map on a location where you wish to find the altitude
  2. The altitude will be displayed in the message box below the map and when you hover over the marker
  3. You can click to place more than one marker and return to hover over each in order to find out the altitude again
  4. Click the [Clear Map] button in order to remove all markers and start again
  5. Use the search option to find a place

You can also access a CSV list of latitude, longitude, altitude in meters and altitude in feet for every marker you place on the map.

How it Works

var output_lat =new Array(0);
var output_lng =new Array(0);
var output_f =new Array(0);
var output_m =new Array(0);
var outputDiv=document.getElementById('outputDiv');
var map;
var routeMarkers=new Array(0);
var geocoder;

function initialize()
{
var latlng = new google.maps.LatLng(0,0);
//setCursor:'crosshair'
var myOptions = {zoom:1,center:latlng,mapTypeId:google.maps.MapTypeId.ROADMAP,draggableCursor:'crosshair',mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},scaleControl:true};
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

// Create ElevationService
elevator = new google.maps.ElevationService();

// Add a listener for the click event and call getElevation on that location
google.maps.event.addListener(map, 'click', getElevation);

geocoder = new google.maps.Geocoder();
}

function foundsingle(first)
{
var latlng = new google.maps.LatLng (parseFloat(first.lat),parseFloat(first.lng));

var obj=new Object();
obj.latLng=latlng;

getElevation(obj);
}

function getElevation(event)
{
var locations = [];

// Retrieve the clicked location and push it on the array
var clickedLocation = event.latLng;
locations.push(clickedLocation);

// Create a LocationElevationRequest object using the array's one value
var positionalRequest = {'locations': locations};

// Initiate the location request
elevator.getElevationForLocations(positionalRequest, function(results, status)
{
if (status == google.maps.ElevationStatus.OK)
{
// Retrieve the first result
if (results[0])
{
// Open an info window indicating the elevation at the clicked position
outputDiv.innerHTML= "Last point clicked : " + results[0].elevation.toFixed(3) + " m / " + (results[0].elevation*3.2808399).toFixed(3) + " feet";
var marker=placeMarker(clickedLocation,results[0].elevation.toFixed(3) + " m / " + (results[0].elevation*3.2808399).toFixed(3) + " feet");
marker.setMap(map);
routeMarkers.push(marker);

output_lat.push(event.latLng.lat());
output_lng.push(event.latLng.lng());
output_f.push((results[0].elevation*3.2808399).toFixed(3));
output_m.push(results[0].elevation.toFixed(3));

ftn_makecsv();
}
else
{
outputDiv.innerHTML="No results found";
}
}
else
{
outputDiv.innerHTML="Elevation service failed due to: " + status;
}
});
}

function placeMarker(location,text)
{
var image = new google.maps.MarkerImage('http://www.daftlogic.com/images/gmmarkersv3/stripes.png',
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(20, 34),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(9, 33));
var shadow = new google.maps.MarkerImage('http://www.daftlogic.com/images/gmmarkersv3/shadow.png',
// The shadow image is larger in the horizontal dimension
// while the position and offset are the same as for the main image.
new google.maps.Size(28, 22),
new google.maps.Point(0,0),
new google.maps.Point(1, 22));

var marker = new google.maps.Marker({position:location,map:map,shadow:shadow,icon:image,title:text});

return marker;
}

function clearmap()
{
if (routeMarkers)
{
for (i in routeMarkers)
{
routeMarkers[i].setMap(null);
}
}
routeMarkers=new Array(0);
clearsearchresults();
document.getElementById("queryInput").value="";
outputDiv.innerHTML="";

output_lat =new Array(0);
output_lng =new Array(0);
output_f =new Array(0);
output_m =new Array(0);

document.getElementById("ta_csvoutput").style.visibility="hidden";
document.getElementById("ta_csvoutput").value="";
}

function ftn_makecsv()
{
var int=0;
document.getElementById("ta_csvoutput").style.visibility="visible";
document.getElementById("ta_csvoutput").value="";

output="number";
if (document.getElementById("cb_output_latlng").checked)
{
output+=",latitude,longitude";
}
if (document.getElementById("cb_output_meters").checked)
{
output+=",meters";
}
if (document.getElementById("cb_output_feet").checked)
{
output+=",feet";
}
output+="\n";


for (i in routeMarkers)
{
output+=int;
if (document.getElementById("cb_output_latlng").checked)
{
output+=","+output_lat[int]+","+output_lng[int];
}
if (document.getElementById("cb_output_meters").checked)
{
output+=","+output_m[int];
}
if (document.getElementById("cb_output_feet").checked)
{
output+=","+output_f[int];
}
output+="\n";
int=int+1;
}
document.getElementById("ta_csvoutput").value=output;
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
ftn_quickfind2(document.getElementById('goto').value);
document.getElementById("goto").focus();
document.getElementById("goto").select();
return false;
}
else
{
return true;
}
}

//***********************************************************************
//*****************Quick Find Option*************************************

function ftn_quickfind2(address)
{
document.getElementById("btn_go").value="Searching...";
geocoder.geocode( { 'address': address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
var image = new google.maps.MarkerImage('http://www.daftlogic.com/images/gmmarkersv3/stripes.png',
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(20, 34),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(9, 33));
var shadow = new google.maps.MarkerImage('http://www.daftlogic.com/images/gmmarkersv3/shadow.png',
// The shadow image is larger in the horizontal dimension
// while the position and offset are the same as for the main image.
new google.maps.Size(28, 22),
new google.maps.Point(0,0),
new google.maps.Point(1, 22));

var point = results[0].geometry.location;

map.setCenter(point);
map.fitBounds(results[0].geometry.viewport);

document.getElementById("btn_go").value="Found";
}
else
{
//alert("Geocode was not successful for the following reason: " + status);
document.getElementById("btn_go").value="Not Found";
}
});
}

Relevant Links

Google Maps API

Version History

Previous Comments For This Page

Thanks a loooot, needed info for architecture project in France as a student, great job
On 15/10/2014
I could previously use this site, but now the map does not display. I'm using OSX Version 10.9.5 and Safari Version 7.1
On 04/10/2014
Your Website is extremely useful.But, as humans, I hope it is not true, you are actually not generous: Why do you block the access of your site to some countries!
By Batman on 02/10/2014
I guess it gives "approximate" data at best, not to be used for any scientific purposes where accuracy is key. I just viewed a location that I know for a fact is higher than another location next to it, but the elevation shown between the two is inaccurate. The two locations I viewed are about 100 meters apart and the one that's higher by a good few meters shows as being 0.020 meters lower. Unfortunately, that's simply impossible.
By Mr. Googler on 22/09/2014
Chris C., honest answer, I'm not sure.
By Daft Logic on 21/09/2014
Does this take into account the geoid variations?
By Chris C. on 20/09/2014
thank you so much. It is very useful for me!
On 15/09/2014
map showing all details help to know the more information . tanks
On 12/09/2014
I think I just figured it out. The elevation showing is the elevation of the sea/ocean bed not the surface of the sea. Sorry.
By Roger on 29/07/2014
Land data seems very accurate. Question though, why the ocean elevations are so far off? aren't they suppose to be at zero? Just wondering and I'm sure you can explain. Thanks!
By Roger on 29/07/2014
Hi Chris, I'm not 100% sure but it is probably from an existing database of sample points. I guess it then gets the average elevation of the location in question based on know values close by.
By Daft Logic on 27/07/2014
Belated thanks for your reply. And how does THAT work (ie how does the Google Elevation API work)? Do they use data already collected by (for example) Ordnance Survey maps, or is there some other way they can figure out elevation?
By Chris on 26/07/2014
Hi Chris, it uses The Google Elevation API.
By Daft Logic on 17/07/2014
This site is incredible, in fact it may even justify that overused word "awesome", but can someone please explain to me how it works? I know there's a section above saying "how it works" but unless you have a PhD in advanced computer wizardry, that section is incomprehensible. Is there a simpler version? How, basically, can you calculate altitude from a 2D map that's essentially "drawn" from above? It's easy (or at least relatively easy) to understand how you calculate latitude and longitude from such a map, but how on earth do you calculate altitude? Meantime, thanks for a great site!
By Chris on 17/07/2014
I needed to know the elevation if a street in London for a wind loading calculation. The data was accurate and correct. Many thanks.
By Rob on 11/07/2014
just came across you guys. really cool! thanks a lot
By marsius on 08/07/2014
Hi Dan, sorry I'm not sure what the question is. Could you give a bit more detail please?
By Daft Logic on 14/06/2014
Hi, measure of elevation is the meter/feet expressed when map was clicked?
By Dan on 11/06/2014
An absolutely invaluable application if you need to "seed" the barometer in your GPS, especially my Garmin 705. Now I can always seed my start location and get a better (more accurate) measure of how high I am and how much I've climbed on a ride. Thank you so much for developing it.
By RetroGrouch.Au on 11/06/2014
excellent, worked fine for me
By Adam El Rashid on 09/06/2014
Just making sure that after the oceans rise due to the collapsing ice-sheet and global warming my house won't be underwater! I'm good. Thanks daftlogic!
By MerriweatherRaven on 14/05/2014
Great program. Really helped me with plotting my bike rides. Thanks for sharing! But which altitude shows the map Baltic, or Adriatic? As we know ther are some differences between two level!
On 11/05/2014
Great program. Really helped me with plotting my bike rides. Thanks for sharing!
By Mark on 09/05/2014
Hi, can you provide some example please?
By Daft Logic on 24/04/2014
doesn't work - checked two specific points I know the height of - and both were incorrect
On 24/04/2014
Great application. I really like that you posted the source. Although you helped me lose a bet to my wife about the altitude of two locations!
By The Duke on 22/04/2014
Further investigations showed that's indeed Google that shifts the coordinates (see my post below). It returns not only the altitude, but also the effective coordinates it has used to calculate it. In my example, Google's location is about one kilometer away from what I asked for. (Interestingly, on a road *not* covered by Street View cars, while my original location *is*. Don't their cars collect altitude data?) One could consider moving the marker on the card to the Google given point, however, while being more honest, this might confuse users.
By Manfred on 25/03/2014
Great job, thanks a lot for sharing this. What I don't understand: When I load coordinates, the resulting location is a bit off, for instance "44.08326909888971,5.0359708070755005" -> "number,latitude,longitude,meters 0,44.0779928,5.0439705,95.814". This is most probably a Google issue, but maybe someone knows a work around?
By Manfred on 21/03/2014
Great site and generally very reliable. But for Mt. Sutro in San. Francisco, CA, I am getting elevations as high as 960', but the hill is only max 908'.
By Jeff on 17/03/2014
Melyik Tenger szint feletti magasságot adja???
On 10/03/2014

30 out of 343 comments shown. See all comments.

Add your own comment below and let others know what you think:

Comments :

Your Name (optional) :