Activate your free membership today | Log-in

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.

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

Posted by Dion Almaer at 7:46 am

+++--
3.3 rating from 19 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.