Thursday, May 8th, 2008

Location APIs: The Discussions

Category: Gears, JavaScript

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

Aza Examples

javascript

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

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.

Posted by Dion Almaer at 8:09 am
2 Comments

+++--
3.9 rating from 14 votes

2 Comments »

Comments feed TrackBack URI

Has anyone tried the GpsGate web services?
http://gpsgate.com/index.php?id=68

Its a very similar approach, it can access both a locally connected GPS (if running the gpsgate client) and position-feeds from any GpsGate Server. As said, would be interesting to discuss a unifying api. Implementing at least parts of your proposal as a gpsgate-wrapper would be quite possible today.

Ajaxian features a post about it aprx six months ago also:
http://ajaxian.com/archives/gpsgate-access-gps-location-information-through-javascript

/ Fredrik @ GpsGate.com

Comment by Fredrik — May 8, 2008

This is great and all, and I can imagine various different uses for such an API…. but how many average users actually have a GPS receiver in their computer/laptop/PDA/smartphone? More of the high-end smartphones are getting GPS receivers, but its still far from becoming common place.

Comment by Unfocused — May 8, 2008

Leave a comment

You must be logged in to post a comment.