Java Reference
In-Depth Information
if(window.localStorage) {
superman = JSON.parse(localStorage.getItem("superman"));
}
The Web Storage API provides a useful way of storing various types of information on a
user's computer without the restriction of cookies. More information about it is available
at SitePoint.
Geolocation
The Geolocation API is used to obtain the geographical position of the device. This means
it can be used to find the user's exact location and then link to nearby places or measure the
speed at which the user is moving. Because of privacy concerns, permission to use this has
to be granted by the user first.
If geolocation is available it will be a property of the navigator object that we met in
Chapter 9 . This property has a method called getCurrentPosition() that will return
a position object to a specified function, called youAreHere() in the example:
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(youAreHere);
}
The position object passed to the youAreHere() function has a coords property
with a latitude and longitude property, which together give the coordinates of the
device. These coordinates can then be used in conjunction with other applications or web
services (such as a mapping service) to obtain the user's exact location. In this example, we
simply show an alert dialog that displays the user's coordinates:
function youAreHere(position) {
alert("Latitude: " + position.coords.latitude + ",
Longitude:
position.coords.longitude);
}
The position object has several other properties that can be used to find out information
about the location and movement of the device:
Search WWH ::




Custom Search