HTML and CSS Reference
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
“ http://maps.google.com/maps?hl=en&ie=UTF8&ll= “ + 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.
FINDING LATITUDE AND LONGITUDE
device or computer. Here's the basic code:
To i lter out browsers that do not recognize the geolocation object, use a simple trap:
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: