W3C Geolocation API

Michael(tm) Smith mike@w3.org

Overview

How does a Web app get access to user location data?

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)

Who’s doing the work?

Where to get it

http://dev.w3.org/geo/api/spec-source.html

Requirements

Requirements (more)

Requirements (more)

Agnostic about location method

Some use cases

Example: “One-shot” query

  function showMap(position) {
    // Show a map centered at
    // at (position.latitude, position.longitude). }
  // One-shot position request.
  navigator.geolocation.getCurrentPosition(showMap);
    

Example: Position updates

  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); }
    

IDL: Geolocation interface

  interface Geolocation { 
    readonly attribute Position lastPosition;
    void getCurrentPosition(in 
      PositionCallback successCallback);
    …
    int watchPosition(in
      PositionCallback successCallback);
    …
    void clearWatch(in int watchId); };

IDL: PositionCallback interface

  interface PositionCallback {
    void handleEvent(in Position position); };

IDL: Position object

  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; };
    

The End

Thanks!

mike@w3.org