Monday, October 8th, 2007

GPSGate: Access GPS location information through JavaScript

Category: JavaScript, Library

Johan Franson has developed a solution to access a local GPS through Javascript /
cross-scripting. His library works in all browsers with that dynamically can include
.js script files. Including Firefox, Opera, Opera Mobile and IE.

You need to install a program called GpsGate on the client computer which currently only works for Windows and Pocket PC:

“GPS in browser” uses cross scripting. GpsGate runs a small local web server from which your page can request GPS information. A javascript library is included to make this really simple.

  1. <script type="text/javascript" src="http://localhost:12175/javascript/GpsGate.js"></script>
  2.  
  3. <script type="text/javascript">
  4.   //< !&#91;CDATA&#91;
  5.  
  6.  // That is the callback function that is specified in getGpsInfo() and
  7.  // executed after the data is returned
  8.  // See more info on the returned "gps" object below.
  9.  
  10.     if (typeof(GpsGate) == 'undefined' || typeof(GpsGate.Client) == 'undefined')
  11.     {
  12.         alert('GpsGate not installed or not started!');
  13.     }
  14.  
  15.     function gpsGateCallback(gps)
  16.     {
  17.         var resultTag = document.getElementById('position');
  18.         resultTag.innerHTML = 'longitude:' + gps.trackPoint.position.longitude +
  19.                               ' latitude:' + gps.trackPoint.position.latitude;
  20.  
  21.         var d = new Date(gps.trackPoint.utc);
  22.  
  23.         resultTag = document.getElementById('time');
  24.         resultTag.innerHTML = d.toLocaleString();
  25.     }
  26.  
  27.  //&#93;&#93;>
  28. </script>
  29.  
  30. <div id="position"></div>
  31.  
  32. <div id="time"></div>
  33.  
  34. <form name="f1">
  35. <input value="GPS info" type="button"
  36.                         onclick='JavaScript:GpsGate.Client.getGpsInfo(gpsGateCallback)'
  37.                         id=button1 name=button1/>
  38. </form>

Posted by Dion Almaer at 7:46 am
7 Comments

+++--
3.4 rating from 28 votes

7 Comments »

Comments feed TrackBack URI

I wonder about the security/privacy issues behind this. If this were dropped onto a web site, and a user with the app was directed to it, couldn’t a bad guy find out someone’s exact (well, just about) location?

Comment by Michael Trythall — October 8, 2007

Such applications/features must use a whitelist of domains.
Interesting idea though.

Comment by Mathieu 'p01' Henri — October 8, 2007

Security is very important here.

There is a white list and a black list. The lists can live for ever or during a session. If a page makes a request for a page, the user is notified and will have to white or black list the site the page comes from.

A page cannot access the GPS position without the users knowledge.

Comment by Johan Franson — October 8, 2007

Dammit!

I was going to do this… you beat me to it Johan. Nice job, I might have to check it out

Comment by D — October 8, 2007

other Javascript location APIs:
Garmin’s Communicator lets you do this with Garmin units – as well as pull off waypoints and tracks.

Skyhook Wireless’ Loki provides Javascript hooks to WiFi Geolocation.

Comment by Andrew Turner — October 8, 2007

@Andrew. As I understand it, the Garmin variant needs a browser plugin to work so its not quite comparable to the “pure” GpsGate XSS solution.

Comment by Fredrik — October 9, 2007

@Andrew – for people looking to implement the Loki Javascript API go to: http://loki.com/developers/

If you’re interested in playing with real-time user geolocation data, check Loki out and play with the js api. Loki offers a white/blacklist by domain and prompts the user when location is requested. If you have feedback/questions feel free to email me at rsarver skyhookwireless.com

Comment by Ryan Sarver — October 11, 2007

Leave a comment

You must be logged in to post a comment.