HTML and CSS Reference
In-Depth Information
GEOLOCATION
h e geolocation object is part of the navigation object in the HTML5 DOM. It's a
means of i nding your location, more or less. In several tests, it successfully located the
ballpark of my location. h e most important attributes of the geolocation object are the
latitude and longitude attributes. h at's because, with those values, you can load a map
of your general location.
Creating an HTML page that shows users their latitude and longitude is i ne, but HTML5
browsers are also able to load a map into their Web sites using Google Maps. h e URL for this
capability is:
“ http://maps.google.com/maps?hl=en&ie=UTF8&ll= “ + latitude + “, “ + longitude +
“&spn=0.054166,0.110378&z=13&output=embed”
h e latitude and longitude variables contain coordinate values. So, the trick is to locate
the latitude and longitude values to insert where they're needed.
FINDING LATITUDE AND LONGITUDE
Getting these values requires pretty straight JavaScript from your browser — on your mobile
device or computer. Here's the basic code:
306
navigator.geolocation.getCurrentPosition(someFunction);
To i lter out browsers that do not recognize the geolocation object, use a simple trap:
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(someFunction);
}
else
{
alert(“Geolocation not recognized”)
}
h is tells users whether their browsers even recognize geolocation .
h e function called to get the position information makes the call but is expected to include a
parameter that will store the actual information about location. Following the practice of
using objects and methods the call is made:
...
navigator.geolocation.getCurrentPosition(LocationMaster.lookUpPosition);
...
h is, in turn, gets the method that returns the requested values:
 
Search WWH ::




Custom Search