Blog Stats
  • Posts - 95
  • Articles - 0
  • Comments - 19
  • Trackbacks - 0

 

Getting Location On A Mobile WebPage

Both Mobile Safari (in iPhone OS 3.0) and Google Android now both support getting the location of the current user.

How cool is that.   Finally mobile web-pages can be location aware.    The user is prompted for whether they wish to enable this facility on a per site basis.

Here’s the HTML/Javascript that does it all.

 

photo

 

<html>

<head>

<script>

navigator.geolocation.getCurrentPosition(foundLocation, noLocation);

function foundLocation(position)
{
  var lat = position.coords.latitude;
  var long = position.coords.longitude;
alert('Found location: ' + lat + ', ' + long);

}
function noLocation()
{
  alert('Could not find location');
}

</script>

</head>

<body>
<h1>Location App</h1>
</body>
</html>

 
 
In the above example  when the location is found it displays current location.
I’ve posted a slightly more feature rich version at http://www.binaryrefinery.com/location.htm
 
 
 
 

Feedback

No comments posted yet.


Post a comment





 

 

 

 

Copyright © Richard Jones