The API requires browser support; either the device a browser is running on must directly expose one or more location-sensing mechanisms (e.g., GPS) to the browser, or some other third-party application must expose it to the browser (e.g., WiFi positioning through SkyHook)
function showMap(position) {
// Show a map centered at
// at (position.latitude, position.longitude). }
// One-shot position request.
navigator.geolocation.getCurrentPosition(showMap);
function scrollMap(position) {
// Scrolls the map so it is centered
// at (position.latitude, position.longitude). }
// Request repeated updates.
var watchId =
navigator.geolocation.watchPosition(scrollMap);
function buttonClickHandler() {
// Cancel when user clicks button
navigator.geolocation.clearWatch(watchId); }
interface Geolocation {
readonly attribute Position lastPosition;
void getCurrentPosition(in
PositionCallback successCallback);
…
int watchPosition(in
PositionCallback successCallback);
…
void clearWatch(in int watchId); };
interface PositionCallback {
void handleEvent(in Position position); };
interface Position {
readonly attribute double latitude;
readonly attribute double longitude;
readonly attribute double accuracy;
readonly attribute double altitude;
readonly attribute double altitudeAccuracy;
readonly attribute double heading
readonly attribute double velocity
readonly attribute DOMTimeStamp timestamp; };
Thanks!
mike@w3.org