Sunday, April 6, 2008

Maemo Mapper paths.db break down


When connected to GPS mapper has a track log in the paths.db file in /home/user/.maemo-mapper/. If you take a look at the file with the sqlite3 client you'll see a table named track_path. This is where the data points are stored but they're not in degrees. A .schema reveals that the columns are called unitx and unity.


A dig through the internet found me source that was using a function called unit2latlon. So I downloaded the source from the garage and grep'd for the definition of this function. It turns out to be a macro in defines.h.


Here's the macro converted to ruby for easy use. It only does long and lat. I still have to find what the altitude is in...



TILE_SIZE_P2 = 8
MAX_ZOOM = 20

WORLD_SIZE_UNITS = 2 << MAX_ZOOM + TILE_SIZE_P2

MERCATOR_SPAN = -6.28318377773622
MERCATOR_TOP = 3.14159188886811


def unit_2_lat_lon(unitx, unity)
lon = ((unitx) * (360.0 / WORLD_SIZE_UNITS)) - 180.0
lat = (360.0 * (Math.atan( Math.exp ((unity * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) + MERCATOR_TOP)))) * (1.0 / Math::PI) - 90.0;
return lat,lon
end



It's line for line the same as the Maemo-Mapper team's code. There was a lot more in the defines.h file, but this is all that's needed to run the function. I ran the last point in the database and checked the output in Google maps (straight copy and paste!) and it is where it stopped logging!



irb(main):001:0> lat,lon = unit_2_lat_lon(157094175,199470581)
=> [41.9127500226541, -74.6601469069719]

No comments: