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

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
First of all I want to say thanks to the developer of this great application. By using a portable GPS Garmin GPSMAP 76CSx I have verified the results and its only produce about 0.1 percent difference in the 523 metres of altitude measurement (loc: Tentena, near Poso Lake, Sulawesi, Indonesia). Thank you very much for sharing.
By Yoppy Soleman on 21/02/2014
Hi, yes, according to [https://developers.google.com/maps/documentation/javascript/markers#complex_icons], shadows are now ignored and not displayed.
By Daft Logic on 20/02/2014
Do you know, why the shadow.png icon doesn't work?
By Alan on 19/02/2014
CRAIG, there is no issue as far as we are aware. Can you try deleting your temporary internet files or try a different web browser please?
By Daft Logic on 18/02/2014
this past week this just does not load is there an issue ??
By CRAIG on 17/02/2014
Works great, and its elevations match various cross references I check routinely. Super tool -- keep up the great work, Google Daft!
By Maurice on 14/02/2014
Good stuff indeed. Quick and easy to use. THANKS GOOGLE%uD83D%uDC4D
On 22/01/2014
Hi, I'm not sure. It is an estimate of elevation via https://developers.google.com/maps/documentation/elevation/
By Daft Logic on 21/01/2014
Is this measuring Mean Sea Level (MSL) or Above Ground Level (AGL) or Height Above Ellipsoid (HAE)?
On 21/01/2014
please help me to configure this for my website. Marker is not showing.
By gaurav on 21/01/2014
please help me to configure this for my website. Marker is not showing.
On 21/01/2014
how to use it? please provide documentation.
On 21/01/2014
had my home elevation correct within .2', or 2.4". Not bad at all!
By D on 17/01/2014
I live on a lake. As pictured on the map the water was calm when photographed. I moved about taking readings at random points on the water and got varying altitude results. Interesting.
By Steve on 03/01/2014
Brilliant, thanks!
By SunnyBrighton on 02/01/2014
What is the absolute accuracy of the elevation reading above sea level?
On 10/12/2013
Matt, This should now work.
By Daft Logic on 23/11/2013
It no longer drops a pin when you do a search. It brings you do the general area on the map but it used to place a pin at that exact search location. I have tried in Firefox, Chrome and IE.
By Matt on 21/11/2013
Hi Bryan, could you delete your temporary internet file then reload the page again to see if this helps?
By Daft Logic on 20/11/2013
Is anyone else finding that its not working?
By Bryan on 20/11/2013
Brilliant. was looking for a new xc bike route and this really helps avoid those nasty hills
On 20/11/2013
Thanks for providing this excellent tool. I tried to get a map (or just altitude information from FEMA) -- Forget it! DaftLogic was easy to use. In fact, it was fun. The price was certainly right...
By Elizabeth on 16/11/2013
Does not work with Win7 PC running latest version of Mozilla.
By jessejames49us on 07/11/2013
very nice information on elevation data for generating contour maps.
By Mr. S,B.Hiremath on 25/10/2013
need current elevation needed
On 24/10/2013

30 out of 318 comments shown. See all comments.

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

Comments :

Your Name (optional) :