Location providers - climb the Triglav with Android

Tutorials with advanced 'difficulty' and more Lines of Code.

Location providers - climb the Triglav with Android

Postby paller » Wed Feb 20, 2008 10:30 pm

Click here for the cross-linked version of the entry

Android SDK as it is clearly encourages developers to deal with location-aware applications. Both the location provider and the map part of the system is sufficiently documented and is functional which is pretty much in contrast with e.g. the synchronization and bluetooth parts. Good tutorials have been written about how to use the Android location framework so I wanted to try something else. I wanted to see, how to introduce one's own location data into the system.

Android SDK comes with one built-in location provider called "gps". This location provider moves along a predetermined route - obviously around Google premises. I was curious whether it is possible to introduce one's own location provider into the system therefore I took apart android.server.LocationProviderService. I found that it is relatively easy to introduce one's own location track which is then presented as new location provider to Android applications. Creating a new location provider software module turned out to be more complicated and eventually I did not try that out. LocationProviderService is able to handle location providers with their own Java logic but unfortunately the classes of these providers are loaded by the own classloader of LocationProviderService. This means that it is not possible to deploy the location provider software module as a package (apk), one has to fiddle with the software base of the Android system.

I did not do it because, to my pleasant surprise, Android's own location provider turned to be a pretty versatile simulator itself. Deploying own location providers based on track data really works like a charm. The LocationProviderService loads providers from under the /data/misc/location directory (device-based path). Each subdirectory under this directory is a location provider and the name of the location provider equals to the name of the subdirectory. The files in the subdirectory define the provider. As an example, you can go to the tools subdirectory of the example program package and run pull_gps.bat (emulator needs to be running when you do this). This batch file will fetch the three files associated with the "gps" provider as gps_location, gps_nmea and gps_properties (their original names on the device are location, nmea and properties, respectively, under the subdirectory called gps). The properties file describes the properties of the location provider in an easy to understand textual format. The location file is the last known location and the nmea is the track info in NMEA format. Well, I am not familiar with location format and I don't know what NMEA format is. There are two other possibilities: instead of "nmea" file, you can have "kml" or "track". In case of "kml", the track data is in KML format while "track" is a very simple textual format. I went for the latter and didn't try the former one - erm, I left that execise to the interested reader. ;-)

You can download the example program from here

The "track" format is simple. It looks like this:

time longitude latitude altitude [bearing speed]

where is in milliseconds and is zero-based (first location has 0 timestamp) and bearing and speed can be omitted. LocationProviderService will emit location update intent broadcasts according to the timestamps in the file. Now the only thing remained to solve was how to get those track files. I don't have GPS receiver so I looked around on the Internet and I found a Slovenian mounteneering and hiking website (for those not from Central Europe, Slovenia is a lovely country just between Austria and the Adrian seashore). This has hiking path section with GPS tracks and they have even two tours to the magnificient Triglav peak. I have good memories of that peak because we spent once one week beside the Bohinj glacier lake and Triglav was visible from some of the peaks around the lake. We did not climb it because there was our baby boy with us but I was told that if you take that peak seriously (it is nearly 3000 meters high) then it is accessible by almost anyone. Just don't go in slippers, take an entire day and you will be able to climb it.

The tools subdirectory contains the ozitotrack tool that I created for standard J2SE (so it is not an Android application :-)). The hiking track I downloaded is located in the triglavMT.plt file. Run the tool like the following:

java ozitotrack -s20 triglavMT.plt triglav

This will create triglav_track and triglav_location files. The -s switch instructs the tool to divide time interval among location fixes by 20 - the original track took 3 hours to complete, this will shorten it to just over 8 minutes. For the third file, triglav_properties, I took the gps_properties file (pulled from the emulator with the pull_gps script) and edited it. Now we have the three files needed for the location provider, let's upload it into the emulator.

push_provider.bat triglav

Again, you need to have the emulator running when you execute this command. Then unfortunately you have to restart the emulator - LocationProviderService loads the provider data at startup. Now you are ready to go. Upload the LocationProvider.apk package into the emulator (see the Start here on the right pane to learn, how to do it) and start it.

Image

We have another provider called "triglav" beside the original "gps" provider. Select that provider and launch the "Display location" menu item. You will see us climbing the Triglav peak in 8 minutes (the altitude rises steadily to almost 3000 meters). When we reach the peak, we go back on our track to the origin and so on, this is the property of LocationProviderService.

Don't forget to look around on the peak, the panorama is said to be magnificient.
paller
Developer
Developer
 
Posts: 29
Joined: Mon Dec 31, 2007 2:33 am
Location: London

Top

Postby res » Thu Feb 21, 2008 4:51 am

Excellent write up paller, 5 stars :idea:
res
Senior Developer
Senior Developer
 
Posts: 146
Joined: Tue Nov 20, 2007 8:14 pm
Location: United States

Postby bavarol » Fri Feb 22, 2008 11:00 pm

Hi Paller, I have seen in build.xml, you develop your apps with the last sdk, does it mean, that this project run only under sdk m5?

Eclipse can't load that manifest, there is no entry point, also no activity class, you define like that
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <activity android:name="LocationProviderList" android:label="LocationProviderList">
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


If that's properly for the last sdk, how can I transcribe for m3rc 22? (If possible).

Thx

Kind Regards
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Postby paller » Fri Feb 22, 2008 11:46 pm

bavarol wrote:Hi Paller, I have seen in build.xml, you develop your apps with the last sdk, does it mean, that this project run only under sdk m5?


Yes, the last SDK changed pretty many things, including the manifest schema.

bavarol wrote:Eclipse can't load that manifest, there is no entry point, also no activity class, you define like that
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <activity android:name="LocationProviderList" android:label="LocationProviderList">
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


If that's properly for the last sdk, how can I transcribe for m3rc 22? (If possible).


I think it is possible although I did not try myself. Note that the definition of own content provider is undocumented which means that it can change at any moment, without warning. I didn't check what was the situation in M3 RC22.

Here is a blog entry about the transformation to M5, you can use it backward.

The rocky road to M5

Personally, I believe that you would be better off migrating to M5. It is painful but the SDK develops quite dramatically. If you stay behind, you won't recognize Android very soon. :?
paller
Developer
Developer
 
Posts: 29
Joined: Mon Dec 31, 2007 2:33 am
Location: London

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests