Results 1 to 7 of 7

Thread: HOWTO: Track your position using a GPS dongle and Google Earth

Threaded View

  1. #1
    Join Date
    Feb 2009

    HOWTO: Track your position using a GPS dongle and Google Earth

    This tutorial is designed to guide you through doing exactly what the title says it does. I must profess I am not an expert and have only been using a Linux based system for a couple of weeks. As a result I will more than likely struggle to answer any of your questions, but I will endevour none the less to help as much as I can anyway.

    The method described below was carried out on an 900 Eee PC running Easy Peasy (I could not get this to work using Eeebuntu). Most of the information is from third party sources that I have cobbled together into this one tutorial, references wherever possible.

    Please point out any mistakes. I will try and adapt it at some point to draw polylines as well.

    1. Install Google Earth
    1. Download Google Earth from the Google Earth Website. I am running v4.3 as my Eee is only wee. This can be chosen on the second page of the download process.
    2. Save the file to your desktop and call it GoogleEarthLinux.bin.
    3. Open terminal and type the following three lines one at a time:

      cd ~/Desktop chmod +x GoogleEarthLinux.bin sudo ./GoogleEarthLinux.bin
    4. Leave the default options and click Begin Install.
    5. Once it has finished click Quit not Start as this will run the programme as root which is not a good idea.
    6. Check that Google Earth works. Under Applications => Internet. To get the best results from GE turn Atmosphere off: View => Atmosphere.
    7. Delete the bin file on the desktop and close terminal.


    2. Pairing With Bluetooth GPS Dongle
    1. Enable Bluetooth on you machine. If you do not have built-in bluetooth (like my Eee), then you will need a USB dongle; a couple of quid from eBay.
    2. It is likely that you will not be able to pair your device using the bluetooth wizard as there is unlikely you will be able to enter a passcode on your dongle. So we need to get it to do it the other way round. Re-open terminal and scan for the device using:

      hcitool scan
    3. Write down the MAC address of your GPS dongle. For example 03:3F:AE:98:00:DA.
    4. Enable the authentication of your GPS dongle with the following line. Note: no response will be printed within terminal.

      sudo hciconfig hci0 auth
    5. Create a connection with the device:

      sudo hcitool cc 03:3F:AE:98:00:DA
    6. A pop-up will appear asking you to enter the PIN for your dongle. This should be somewhere in your original documentation. If you don't have it try something generic like 0000, 1111 or 1234.
    7. Click on the bluetooth icon in the menu bar top-right and see how you now have a pairing.


    3. Edit rfcomm.conf
    1. In terminal type the following:

      sudo gedit /etc/bluetooth/rfcomm.conf
    2. This will open the file as the root user and allow you to make changes.
    3. Add the following lines to the bottom of the file:

      rfcomm4 { bind no; device 03:3F:AE:98:00:DA; channel 1; comment "GPS Bluetooth Dongle";
    4. Save the file.


    4. Establish the RF Communication
    1. In a new terminal window type the following:

      sdptool add --channel=1 OPUSH
    2. This should return something like:

      OBEX Object Push service registered
    3. Now type the following:

      sudo rfcomm bind /dev/rfcomm4 03:3F:AE:98:00:DA

    5. Read Data from the GPS Dongle
    1. In terminal type the following:

      cat /dev/rfcomm4
    2. You should see a steady stream of data being read from the GPS device.


    6. Create KML File
    1. Create a new folder to keep the KML file in:

      sudo mkdir /opt/google-earth/realtime
    2. Open text Editor as root user. In terminal type:

      sudo gedit
    3. Copy and paste the following code:

      <?xml version="1.0" encoding="UTF-8"?> <kml xmlns=""> <NetworkLink> <name>Realtime GPS</name> <open>1</open> <Link> <href>./realtime/Realtime GPS.kml</href> <refreshMode>onInterval</refreshMode> </Link> </NetworkLink> </kml>
    4. Save the file as /opt/google-earth/realtime/Realtime GPS.kml
    5. Navigate to the file using File Browser and double-click it. It should automatically open up in Google Earth. In the "Places" section on the right the KML file will be listed under Temporary places. To make the KML file available everytime you load Google Earth right-click it and select "Add to my places".
    6. Right-click the XML in Google Earth and create a Network link to the KML file on your hard drive.


    7. Create GPS Data Server
    1. For this part you will need to find out the baud rate of your GPS dongle. This should be included in the technical specification for the device. Failing that contact the manufactuer directly. My baud rate is 38400.
    2. Install the python serial package from terminal:

      sudo apt-get install python-serial
    3. Open Text Editor as root user again from terminal (sudo gedit).
    4. Copy and paste the following code into the file:

      #!/usr/bin/python # Copyright (C) 2007 by Jaroslaw Zachwieja <grok!> # Copyright (C) 2008 by TJ <linux!> # Published under the terms of GNU General Public License v2 or later. # License text available at import serial import string import sys import getopt def usage(): print "Usage:" print " -p | --port <device> e.g. /dev/rfcomm4" print " -b | --baud <speed> e.g. 38400" print " -f | --file <filename> e.g. /opt/google-earth/realtime/Realtime GPS.kml" print " -h | --help display options" def main(): # defaults serial_port = "/dev/rfcomm4" serial_baud = 38400 file = '/opt/google-earth/realtime/Realtime GPS.kml' try: opts, args = getopt.getopt(sys.argv[1:], "p:b:f:h", ["port=", "baud=", "file=", "help"]) except getopt.GetoptError: usage() sys.exit(1) else: for opt, arg in opts: if opt in ("-p", "--port"): serial_port = arg elif opt in ("-b", "--baud"): serial_baud = string.atof(arg) elif opt in ("-f", "--file"): file = arg elif opt in ("-h", "--help"): usage() sys.exit(0) else: print "Unknown option" gps = serial.Serial(serial_port, serial_baud, timeout=1) print "Serving data from %s (%d baud) to %s" % (serial_port, serial_baud, file) latitude = 0 longitude = 0 speed = 0 heading_in = 0 altitude = 0 range = 1000 tilt = 30 while 1: line = gps.readline() datablock = line.split(',') if line[0:6] == '$GPRMC': latitude_in = string.atof(datablock[3]) longitude_in = string.atof(datablock[5]) try: altitude = string.atof(datablock[8]) except ValueError: # use last good value altitude = altitude speed_in = string.atof(datablock[7]) try: heading_in = string.atof(datablock[8]) except ValueError: # use last good value heading_in = heading_in if datablock[4] == 'S': latitude_in = -latitude_in if datablock[6] == 'W': longitude_in = -longitude_in latitude_degrees = int(latitude_in/100) latitude_minutes = latitude_in - latitude_degrees*100 longitude_degrees = int(longitude_in/100) longitude_minutes = longitude_in - longitude_degrees*100 latitude = latitude_degrees + (latitude_minutes/60) longitude = longitude_degrees + (longitude_minutes/60) speed = int(speed_in * 1.852) range = ( ( speed / 100 ) * 350 ) + 650 tilt = ( ( speed / 120 ) * 43 ) + 30 heading = heading_in if speed < 10: range = 200 tilt = 30 heading = 0 output = """<?xml version="1.0" encoding="UTF-8"?> <kml xmlns=""> <Placemark> <name>%s km/h</name> <description>^</description> <LookAt> <longitude>%s</longitude> <latitude>%s</latitude> <range>%s</range> <tilt>%s</tilt> <heading>%s</heading> </LookAt> <Point> <coordinates>%s,%s,%s</coordinates> </Point> </Placemark> </kml>""" % (speed,longitude,latitude,range,tilt,heading,longitude,latitude,altitude) f=open(file, 'w') f.write(output) f.close() ser.close() if __name__ == "__main__": main()
    5. Save the file as /opt/google-earth/
    6. Now this file needs to be made executable:

      sudo chmod +x /opt/google-earth/

    8. Create Application Launcher
    1. Lastly we need to create an application launcher that will execute the commands to get all the above working in one go each time you use it. Open Text Editor as root user again (sudo gedit in Terminal). Copy and paste the following code:

      #!/bin/bash sdptool add --channel=1 OPUSH sudo rfcomm bind /dev/rfcomm4 03:3F:AE:98:00:DA /opt/google-earth//googleearth %f sudo /opt/google-earth/ exit
    2. Save the file as /opt/google-earth/
    3. Give the file the right privaleges. In terminal:

      sudo chmod a+x /opt/google-earth/
    4. Now we will create a shortcut to it from your application menu. Open the Main Menu application: Preferences => Main Menu
    5. Select "Internet" on the left and then "New Item" on the right.
    6. Enter the following information: Type- Application in Terminal; Name- Google Earth Track; Command- /opt/google-earth/; Comment- Real-time GPS Tracking in Google Earth.
    7. If you want the SVG version of the Google Earth icon one can be found here, but you can work out how to do that bit for yourself.
    8. Hit close and check to see if it is in your applications menu.
    9. Remove your USB bluetooth dongle and restart the machine.
    10. Once it has loaded, plug in your USB dongle and launch Google Earth Track from the applications menu. Note: you have have to select Google Earth Track the first time you run Google Earth after the computer has finished booting.
    11. You will be required to enter your sudo password in terminal. If anyone knows of a way to get around this please post below.
    12. You should now be good to go!
    Last edited by daved2424; May 20th, 2009 at 10:44 AM. Reason: Added point about creating a network link.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts