Ajax Blog


Location APIs: The Discussions

Posted in Ajax News by Dion Almaer on the May 8th, 2008

The Gears community is discussing a Geo Location API, which Aaron Boodman mentioned "was recently proposed to the W3C WebAPI group."

Aza Raskin just posted today about Geolocation in Firefox and Beyond which covers his thoughts on an API.

I thought it would be fun to look at the proposed APIs:

Gears Examples

JAVASCRIPT:
  1.  
  2. var geo = google.gears.factory.create('beta.geolocation');
  3.  
  4. // Get the position.
  5. geo.getCurrentPosition(function(position) {
  6.   updateMap(position.latitude, position.longitude);
  7. });
  8.  
  9. // Watch the position over time.
  10. var watchId = geo.watchPosition(function(position) {
  11.   updateMap(position.latitude, position.longitude, position.accuracy);
  12. });
  13.  
  14. geo.clearWatch(watchId);
  15.  
  16. // Only get the position if the last known position is more than a minute old.
  17. var now = new Date().getTime();
  18. var threshold = now - 60000;
  19.  
  20. if (geo.lastPosition &&
  21.     geo.lastPosition.timestamp.getTime()> threshold) {
  22.   updateMap2(geo.lastPosition);
  23. } else {
  24.   loc.getCurrentPosition(function(position) {
  25.     updateMap2(position);
  26.   });
  27. }
  28.  

Aza Examples

JAVASCRIPT:
  1.  
  2. var geolocator = new navigator.GeolocationRequest();
  3. geolocator.request(function(location) {
  4.   alert( location.latitude + ', '+ location.longitude + ", " + location.accuracy );
  5. });
  6.  
  7. var geolocator = new navigator.GeolocationRequest();
  8. geolocator.request({
  9.   success: function(location) { /* We've got the location! */ },
  10.   error: function(err){ /* There was an error getting location. */ },
  11.   accuracy: "neighborhood"
  12. });
  13.  

There is also a lot of talk around privacy and accuracy, and Apple has their own location manager too.

I hope that we can unify some of this, and give the browsers a geo location API soon. One simple JavaScript abstraction will enable a lot of great apps.

Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/286074460/location-apis-the-discussions

Comments are closed.