HTML5 Samples
July 16th, 2010
Step one
You can use standard object testing to determine if the browser supports GeoLocation.
<script>
/**
* This function is the callback which is passed the result from the .getCurrentPosition()
* function. The pos argument can contain more information than just the latitude/longitude,
* such as altitude, accuracy and speed information.
*
* @param object pos The result from the getCurrentPosition() call
*/
function myCallback(pos)
{
var myLatitude = pos.latitude;
var myLongitude = pos.longitude;
}
/**
* Test for GeoLocation support and make the call
*/
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(myCallback);
} else {
alert("Sorry, your browser doesn't appear to support GeoLocation");
}
</script>
Step two
Once you have tested for it, we can then retrieve the position using the getCurrentPosition() method. You pass this method a callback function which you define. This callback function is given an object (if successful), with various properties:
- latitude
- longitude
- altitude (optional)
- accuracy
- altitudeAccuracy (optional)
- heading (optional)
- speed (optional)
- timestamp
Tags: amphee, html5, symfony development india, symfony web devleopment india, web development
This entry was posted on Friday, July 16th, 2010 at 12:45 pm and is filed under HTML 5, web design, web development. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.
Comments are closed.
