W3C home > Mailing lists > Public > public-geolocation@w3.org > July 2014

Geofencing API proposal

From: Marijn Kruisselbrink <mek@google.com>
Date: Fri, 18 Jul 2014 17:51:13 +0100
Message-ID: <CA+OSsVY-Wdc6ZVQf3CXKdmcb0XjBQ69Kb2-CYEyaa=WBiJ1v1w@mail.gmail.com>
To: public-geolocation@w3.org
Hi, I’m a Software Engineer working on blink/chrome at Google. I’m
currently working on brining Geofencing to Service Workers/the web, so here
is a proposal for an API for that.
Use cases

   -

   Companies presenting their Web app based on the user’s locality (e.g.
   showing their membership card # when they’re in a store).
   -

   Web apps for assisting the user based on their locality (e.g. calendars,
   alarms, reminders, accessibility devices and so on).
   -

   Similarly, Web apps showing photo spots, events and transport
   information based on the user’s locality (similar to Google Now)..
   -

   Offers or discounts presented to a user when they’re near a store.

API proposal

[exposed=Window&Worker]

partial interface Navigator {

  readonly attribute Geofenci <http://dev.w3.org/geo/api/spec-source.html>ng
geofencing;

};

partial interface ServiceWork
<https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md>erGlobalScope
{

  attribute EventHandler ongeofenceenter;

  attribute EventHandler ongeofenceleave;

};

The ongeofenceenter and ongeofenceleave events have a “region” attribute
with the relevant GeofencingRegion.

[NoInterfaceObject]

interface Geofencing {

  Promise<undefined> registerRegion(GeofencingRegion region);

  Promise<undefined> unregisterRegion(DOMString regionId);

  Promise<sequence<GeofencingRegion>> getRegisteredRegions();

};

Possible failure reasons for registerRegion include no service worker being
associated with the page, the user not accepting the location request, and
maybe others. If an attempt is made to register a region with the same ID
as that of a region that is already registered, the new region will
override the old region.

Possible failure reasons for unregisterRegion include no region being
registered with the given ID.

The getRegisteredRegions method returns all currently registered regions.

The promise is resolved to a (potentially empty) list of GeofencingRegions
on success, and rejected on failure to get the regions. A possible failure
reason would be no service worker being active for the page. No regions
being registered is not a failure.

Regions are specified by the following API:

[NoInterfaceObject]

interface GeofencingRegion {

  readonly attribute DOMString id;

};

[Constructor(optional String? id, dictionary options), exposed=Window&Worker
]

interface CircularRegion : GeofencingRegion {

  const double MIN_RADIUS = 10;

  const double MAX_RADIUS = 1000;

  readonly attribute double latitude;

  readonly attribute double longitude;

  readonly attribute double radius;

};

All regions may be referred to by a string identifier. Exactly one region
can be registered per identifier.

The radius is specified in meters, and must be between MIN_RADIUS and
MAX_RADIUS (inclusive). The values of MIN_RADIUS and MAX_RADIUS may be
platform dependent.

If no id is provided the empty string is used. Latitude, longitude and
radius must always be provided.
Received on Friday, 18 July 2014 22:10:23 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:51:08 UTC