[OSM-dev] finding correct offline tile folder to use
Jamie Morken
jmorken at shaw.ca
Tue Feb 11 14:33:29 UTC 2014
Hi,
I am making some code to view offline tile folders, and need to find the correct
folder and file using the GPS coordinates. I "reverse engineered" an offline tile
format, and noticed that the folders are determined by longitude and the files in each
folder are determined by latitude. I came up with this formula for longitude to find
which folder to access given a longitude from GPS:
correctLongitudeFolderToUse = (inputLongitude+180)*((2^currentScale)/360)
so if the input longitude is say -120 degrees (west coast) then at a scale
of 16 the formula works out to:
correctLongitudeFolderToUse =(-120+180)*((2^16)/360)
correctLongitudeFolderToUse = 10922.66
This works properly, if I go to the folder with name 10922 the longitude is correct.
I have an error for finding which file to access for latitude though. I use this
formula for latitude:
correctLatitudeFileToUse = (-inputLatitude+90)*((2^currentScale)/180)
so if the input latitude is 40 and the scale is again 16 this is the result:
correctLatitudeFileToUse = (-40+90)*((65536)/180)
correctLongitudeFolderToUse = 18204.44
so in this case it would say the file name should be 18204.jpg in the folder 10922,
however the latitude is incorrect. I think it is a scaling error since for the two poles
and equator the formula works correctly, and also for 30degrees latitude I think it may
work correctly. I think I need a sin or cos term in the formula but not sure.
Any ideas on how to fix the latitude formula?
cheers,
Jamie
More information about the dev
mailing list