Note: Only one application can access the GPS device at a time. It is certainly possible to open a socket though and connect to it to get locations.
We had two primary resources in expanding an application to use GPS. The first was the documentation provided by Maemo, http://maemo.org/development/documentation/how-tos/4-x/maemo_connectivity_guide.html#Location (the last section covers GPS), and the second was David Hautbois' GPSTracer code, https://garage.maemo.org/scm/?group_id=584. If you are interested in finding out more, feel free to check out those sources.
You will need to make sure that all the basics are initialized properly (most of which your code will probably already do). If its missing any of these calls, you might need to add them.
g_type_init(); g_thread_init(NULL); gtk_init(); osso_initialize("appname", "version", FALSE, NULL);
We used the liblocation library as our access point to the GPS. It contains two important structures, LocationGPSDevice which keeps data about the connection to GPSD and stores GPS data (latitude, longitude, etc), and LocationGPSDControl which is used to gain access to GPSD.
#include <location/location-gps-device.h> #include <location/location-gpsd-control.h>
The next step is to initialize a LocationGPSDevice. This will be updated with the newest longitude and latitude whenever your position changes and will even call a callback function for you every time your location changes (in our case location_changed). The key step is registering the “changed” callback. The function you register here will be called (by the liblocation interface) whenever the GPS device's location changes.
LocationGPSDevice *device; device = (LocationGPSDevice *) g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL); g_signal_connect (device, "changed", G_CALLBACK (location_changed), NULL);
Now we will need to get the controls and turn on the GPS device. Here is the snippet we use to do this (based off of the Connectivity Guide and David Hautbois's code).
LocationGPSDControl *control; control = location_gpsd_control_get_default(); location_gpsd_control_request_status (control); printf ("Starting gpsd\n"); location_gpsd_control_start (control); location_gpsd_control_request_status (control); if (control->can_control) { printf ("gpd can be controlled\n"); } else { printf ("gpd can not be controlled\n"); //You may want to abort here }
Earlier we mentioned that we setup a callback that would be called every time the location changed (ours was called location_changed). You will probably want to write one of these as well to serve whatever purpose you are using GPS for.
static void location_changed (LocationGPSDevice *device, gpointer userdata){ printf ("Latitude: %.2f\nLongitude: %.2f\nAltitude: %.2f\n", device->fix->latitude, device->fix->longitude, device->fix->altitude); }
You will need to add the liblocation libraries when compiling. The suggested compile method is as follows:
gcc filename -o executable `pkg-config --cflags --libs gtk+-2.0 liblocation`
GPSTracer is an example program that uses GPS. When run, GPSTracer will show your current latitude, longitude, altitude, etc. It will send your latitude and longitude to a central database. Your location (as well as the location of others running this program) can then be displayed on a google map. It was developed by David Hautbois and then slightly altered by us for this project.
Download our source code form http://ieee.berkeley.edu/misc/gps.tar.gz. The tarball includes the source code for gpstracer and the binary (called gpstracer). scp gpstracer to your Nokia device.
Find a location that has both a WiFi connection and is able to see GPS satellites (This is a nontrivial task). Be aware that it may take five minutes to acquire the satellite signals.
Run ./gpstracer from the terminal
Inside gpstracer, the latitude, longitude, speed, and altitude are written to: http://www.sfjerry.com/gget.php with the variables named as follows: http://www.sfjerry.com/gget.php?lat=17&lon=-117&speed=5&alt=4 The latitude, longitude, and time of observation is written to a SQL database on this server. This is one of a variety of solutions for storing GPS data and retrieving it on a google map. All that is needed is to set up a database, and create a table with latitude, longitude, and time columns. This database will be constantly written to as the gpstracer is running, so some clean-up routines to remove old datapoints may be necessary.
For our tests, the google map location was displayed at www.sfjerry.com/gmap.php. The source code is located here: http://www.sfjerry.com/googlemaps.zip The map displays the latitude and longitude of the latest reading from the database as a marker on the map.
http://david.hautbois.free.fr/joomla/index.php - Location of original GPSTracer.
http://code.google.com/apis/maps/ - Get a google maps Key and find out some Google Maps API