Question: Is geolocation part of HTML5? Why are you talking about it?
Answer: Geolocation support is being added to browsers right now, along with support for new HTML5 features. Strictly speaking, geolocation is being standardized by the Geolocation Working Group, which is separate from the HTML5 Working Group. But I’m going to talk about geolocation in this book anyway, because it’s part of the evolution of the web that’s happening now.
by Mark Pilgrim's Dive into HTML5
| Firefox | IE | Chrome | Safari | Opera | iPhone | Android | BlackBerry | |
|---|---|---|---|---|---|---|---|---|
| Dive into HTML5 | 3.5+ | 9.0+ | 5.0+ | 5.0+ | 10.6+ | ?? | 2.0+ | ?? |
| HTML5 Solutions | 3.5+ | 9.0+ | 5.0+ | 5.0+ | 10.63+ | 3.2+ | 2.1+ | OS 6.0 |
{
coords: {
latitude: [latitude], // degrees
longitude: [longitude], // degrees
accuracy: [accuracy], // meters
altitude: [altitude], // meters
altitudeAccuracy: [altitudeAccuracy], // meters
speed: [speed], // meters/second
heading: [heading],
// angle (clockwise degrees from north)
},
timestamp: [timestamp] // miliseconds
}
{
enableHighAccuracy: [bool],
maximumAge: [milliseconds],
timeout: [miliseconds]
}
{
code: [code], //number
message: [message] //string
}
Error codes
var watchedUser = navigator.geolocation.watchPosition (
successPos,
errorPos,
additionalParams
);
//to clear
navigator.geolocation.clearWatch(watchedUser);
function euclidDistance(x1, y1, x2, y2) {
var r = 6371,
i;
for(i in arguments) {
if(arguments.hasOwnProperty(i)) {
arguments[i] = Math.PI * arguments[i] / 180;
}
}
return r * Math.sqrt(
2 - 2 * (
Math.cos(x1)*Math.cos(x2)*Math.cos(y1-y2) +
(Math.sin(x1) * Math.sin(x2))
)
);
}
function estDistance(x1, y1, y2, x2) {
var fc = 40000 / 360, //km per degree
xDif = x2 - x1,
yDif = y2 - y1;
return Math.sqrt(
xDif * xDif * fc * fc +
yDIf * yDif * fc * fc
);
}