HTML and CSS Reference
In-Depth Information
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:
“ “ + latitude + “, “ + longitude +
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.
Getting these values requires pretty straight JavaScript from your browser — on your mobile
device or computer. Here's the basic code:
To i lter out browsers that do not recognize the geolocation object, use a simple trap:
if (navigator.geolocation)
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:
h is, in turn, gets the method that returns the requested values:
Search WWH ::

Custom Search