HTML and CSS Reference
In-Depth Information
•
altitude
: The height of the position, gathered if the viewing device has the
capability to measure altitude
•
accuracy
and
altitudeAccuracy
: The accuracy of the position as meas-
ured in meters
•
heading
: The direction of travel as measured in degrees around a circle
•
speed
: The speed of travel in a certain heading in meters per second
Note
In addition to the
timestamp
and
coords
properties, Firefox includes an
address
property for retrieving address information such as city, country, and even
street information!
Update the preceding
locatedSuccess()
function to print the location data on-
screen:
function locatedSuccess(geo) {
var lat = geo.coords.latitude;
var long = geo.coords.longitude;
document.body.innerHTML
=
“<ul><li>lat:"+lat+"</li><li>long:"+long+"</li></ul>";
}
An additional function name can be given to the
getCurrentPosition()
meth-
od to specify a function to run when the request for the user's location has failed. Edit
the
init()
code and add a
locatedFailed()
function:
function init() {
// get the current position
//and
call
the
“locatedSuccess"
or
“loc-
atedFailed" if
successful or not
window.navigator.geolocation.getCurrentPosition
(locatedSuccess, locatedFailed);
}
function locatedFailed(e) {
// log the error code and message
console.log(e.code , e.message);
}
Search WWH ::
Custom Search