Home

Post

Feeds

RSS

Aug 23Live GPS Visualizations With AIR & Merapi

So, my co-worked Adam Flater started up the Merapi Project a while back and asked me to contribute. Up until now, the only thing I've had time to contribute was the name. Well, after seeing the cool stuff that he and Jordan were doing at 360|Flex, I decided it was time to step up to the plate, get my shit together, and produce my own kick-ass Merapi demo.

Anyone who has been following the blogs knows that we at UM are real big into GIS and data visualization. Don't believe me? Take a look at SpatialKey to see what we can do with it.

I recorded a screencast where I walk you through the setups and the code of the application:

Java Code:

package com.universalmind.merapi;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import com.diddlebits.gpslib4j.GPS;
import com.diddlebits.gpslib4j.IDate;
import com.diddlebits.gpslib4j.IGPSlistener;
import com.diddlebits.gpslib4j.IPosition;
import com.diddlebits.gpslib4j.ITime;
import com.diddlebits.gpslib4j.Position;
import com.diddlebits.gpslib4j.PositionRadians;
import com.diddlebits.gpslib4j.Garmin.GarminGPS;
import merapi.Bridge;
import merapi.MerapiObject;
import merapi.messages.Message;
public class GPSReader extends MerapiObject implements IGPSlistener{
   GPS gps;      
   Position position = null;
   IPosition current = null;
   BufferedInputStream input;
   BufferedOutputStream output;
   
   public Bridge bridge;
   
   public static void main( String[] args )
   {
      
      new GPSReader();
   }
   
   public GPSReader()
   {
      super();
      
      bridge = Bridge.getInstance();
      
      CommPort port;
      
      try {
         port = CommPortIdentifier.getPortIdentifier("/dev/tty.USA19H1d1P1.1").open("GPSReader", 3000);
      } catch (NoSuchPortException e) {
         System.out.println("/dev/tty.USA19H1d1P1.1 not found!");
         return;
      } catch (PortInUseException e) {
         System.out.println("Port already in use by " + e.currentOwner);
         return;
      }
      
      try {
         input = new BufferedInputStream(port.getInputStream());
         output = new BufferedOutputStream(port.getOutputStream());         
      } catch (IOException e) {
         System.out.println("Error opening /dev/tty.USA19H1d1P1.1");
         return;
      }      
            
      gps = new GarminGPS(input, output);
      gps.setAutoTransmit(true);
      gps.addGPSlistener(this);
      
   }
   
public double getLat() {return __lat;}
   public void setLat(double lat) {
      this.__lat = lat;
   }
   public double getLon() {return __lon;}
   public void setLon(double lon) {
      this.__lon = lon;
   }
   public String getTime() {return __time;}
   public void setTime(String time) {
      this.__time = time;
   }
   public String getDate() {return __date;}
   public void setDate(String date) {
      this.__date = date;
   }
   
   public void dateReceived(IDate d) {
      String dateString = d.getMonth() + "/" + d.getDay() + "/" + d.getYear();
      System.out.println(dateString);
      this.setDate(dateString);
   }
   public void positionReceived(IPosition pos) {
      current = pos;
      this.setLat(toDecimalDegrees(current.getLatitude()));
      this.setLon(toDecimalDegrees(current.getLongitude()));
      Message message = new Message();
      GPSPoint point = new GPSPoint();
      point.lat = this.getLat();
      point.lon = this.getLon();
      point.date = this.getDate();
      point.time = this.getTime();
      message.setData(point);
      try {
         bridge.sendMessage(message);
      } catch (Exception e) {
         
         System.out.println(e.getMessage());
      }
      
   }
   public void timeReceived(ITime t) {
      String timeString = t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
      this.setTime(timeString);
      System.out.println(timeString);
   }
   
   private double toDecimalDegrees(PositionRadians rads){
      return Math.toDegrees(rads.getRadians());
   }
   
   private double __lat = 0;
private double __lon = 0;
private String __time = "";
private String   __date = "";
}

Posted by: Andrew Powell

Categories: Merapi , MapQuest , Java , Flex , General , Adobe , Universal Mind , MapMyPix , Air

Comments

Very cool Andy. Great job.

Jeff Bouley Jeff Bouley
08/23/08 11:31 AM

Cool stuff, Andy!

Tom Link Tom Link
08/23/08 3:08 PM

Hey Andy, Great code..but the QT video isn't loading for the screencast for me. Any way you can put that in flash instead?

@Devo - I will work on it.

Andrew Powell Andrew Powell
09/05/08 8:54 AM

Very cool. Good to see I'm not the only one that is obsessed with GPS :)

I've actually done something very similar with AIR + Merapi using open source software for the mapping and parsing of NMEA-compliant GPS data across USB.

Andrew Trice Andrew Trice
09/14/08 1:31 PM

Write your comment



(it will not be displayed)







About Andrew Powell

More ...

Powered by Mango Blog: a ColdFusion blog engine