Real-time GPS to GMap

A quick mash-up to display GPS position data from a bluetooth GPS device in real-time on a Google map inside a web browser.


Built using a signed processing applet to read NMEA GPS-data from a RoyalTek RBT 2210 via the bluetooth RFCOMM profile (using the bluecove implementation of javax.bluetooth), parse it and send it to a Google map using the Google Maps API, JSObject and JavaScript.


<br />

 

This should be working with other NMEA GPS devices, too. Possibly StupidNMEAParser.parseNMEAString(String s) has to be changed.

 

 

Code snippets

Connecting using the RFCOMM profile:

 

void connect() {
  try {
    StreamConnection con = (StreamConnection)Connector.open(RBTUrl);
    is = con.openInputStream();
  } catch (IOException ioe) {
    ioe.printStackTrace();
  }
}


Read data:


void read() {
  if (is==null) return;
  try {
    char inchar;
    if (is.available()<=0) {
      return;
    }
    while (is.available()>0) {
      inchar = (char)is.read();
      inb.append(inchar);
      if (inchar=='n') {
        parser.parseNMEAString(inb+"");
        inb = new StringBuffer();
      }
    }
  } catch (IOException ioe) {
    ioe.printStackTrace();
  }
}


Parse data:


void parseNMEAString(String s) {
    if (s.indexOf("$GPGGA")==0) {
      try {
        String[] matches = s.split(",");
        String time = matches[1];
        float lat = Float.parseFloat(matches[2]);
        lat /= 100.0;
        lat = floor(lat) + (lat%1)/60.0*100.0;
        if (matches[3].equals("S")) lat = -lat;
        float lng = Float.parseFloat(matches[4]);
        lng /= 100.0;
        lng = floor(lng) + (lng%1)/60.0*100.0;
        if (matches[4].equals("W")) lng = -lng;

        gotPosition(new LatLngTime(lat, lng, time));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
}


Accessing JavaSript:


JSObject window = JSObject.getWindow(this);
...
window.eval("addMarker("+pos.getLat()+","+pos.getLng()+")");


Source Codes

nmea2gmap.zip (100 KB)

applet.zip (272 KB)