Return to Snippet

Revision: 63197
at April 16, 2013 07:46 by heathbo


Initial Code
HTML
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Where am I</title>
        <script src="myLoc.js"></script>
        <link rel="stylesheet" href="myLoc.css">
    </head>
    
    <body>
    	<div id="location">
        	You location will go here.
        </div>
    </body>
</html>


JAVASCRIPT
window.onload = getMyLocation;

function getMyLocation()
{
	if(navigator.geolocation)
	{
		navigator.geolocation.getCurrentPosition(displayLocation);
	}
	else{
		alert("Oops, no geolocation support");
	}
}

function displayLocation(position)
{
	var latitude = position.coords.latitude;
	var longitude = position.coords.longitude;
	
	var div = document.getElementById("location");
	div.innerHTML = "You are at Latitude: "+latitude+ ", Longitude: "+longitude;
}

Initial URL

                                

Initial Description
Html and JavaScript code to see the longitude and latitude of the viewing browser.

Initial Title
JavaScript GeoLocation

Initial Tags

                                

Initial Language
JavaScript