Open Street Maps (OSM) Tile Viewer

DieterR

Member
Licensed User
Longtime User
I like to introduce my sample application that solves frequently ask questions like 'how to show the GPS position in a map', 'how to get free of cost maps' and 'how to prepare maps before going outdoor'. My solution is the use of Open Street Maps (OSM). Several kinds of maps are available and are continuously improved by many 1000 people. The scale goes from the whole earth to a single street. OSM are provided under 'Creative Common License' and can be freely used for personnel purpose.

I hope my sample program will inspire you to implement some improvements and provide it also in the B4P forum. Perhaps as new Open Source project?:) For example: improvements of the graphic, e.g. a nice feature would be a seamless scrolling from one map tile to the next. In the present version only one tile is shown and the change is very 'skippy'.

Short Description: The sample program works by default with the GPS Intermediate Driver. For older devices the item 'AutoGPS' in the .ini file has to be set to 'false', as well COM and Speed has to be adapted. After GPS and Internet connection are established the program downloads the proper Map Tile and shows the GPS position in it. You can zoom in and out by a simple click in the map. Map tiles are automatically stored. Stored tiles will be used next time much faster or when off-line. The tile storage should be in a SD card and may be shared with other programs. If required, change the default path or the Basic URL for the Map source in the .ini file. When GPS is switched off you can select a nearby tile by shift gesture at the map. A numeric menu is available to select Map tiles manually and for understanding how OSM tiles work. The source code includes basic infomations and a link.:)

Now, I am going to implement the OSM tiles 'App' into my outdoor GPS tool. It is a 10.000 lines of code project that was already grown to a real 'Swiss Army Knife' for mobile navigation.:cool: You will find the Freeware by googling to 'KDR GPS Tracker'. By the way, many thanks to the B4P community for a lot of ideas.

Enjoy the 'App'

DieterR
 

Attachments

  • Screen_Dump.jpg
    Screen_Dump.jpg
    27.4 KB · Views: 477
  • OSM_Tiles_V3.zip
    75.8 KB · Views: 435
Last edited:

klaus

Expert
Licensed User
Longtime User
Hi Dieter,
Could you please remove from your zip file all dll's.
During loading the sbp file, B4PPC will automaticaly add all the required libraries.
Removing the dll's will avoid that non licenced user get these libraries.

I didn't have a closer look at your program yet, but will do so.

Best regards.
 

corwin42

Expert
Licensed User
Longtime User
If you want to have a tool for batch downloading OSM tiles have a look at my PDA TileManager.
Of course it is written with Basic4PPC. The program has a feature (Menu->MapView) to view the map offline and scroll it around (even with GPS support).

In the last official version (1.1) the MapViewer has some problems on VGA-Devices (dragging the map is slow). I have fixed this some time ago but didn't have time to release a new version. I think I will make some smaller fixups in the next days and then release the source here as a more complex program example. There is only one small problem. Because of object name conflicts I use a modified version of one of agrahams libraries. Will have a look on it how to solve this in another way.
 

DieterR

Member
Licensed User
Longtime User
Hi Markus,
thank you for your response. Your TileManager looks fine. My intention was to provide the necessary know how to enable others in writing their own OSM Apps.

We should point out, that bulk downloading of OSM Tiles is not desired (see OSM Tile usage policy). Tiles should only be downloaded if they are needed.:rolleyes:

The idea of my program sample was to get the needed map tiles when I am, for example, on a few days lasting bike (or trike) tour. I like to travel at spontaneously planned routes. For such cases it would not be economically to download all eventually needed map tiles at the required higher zoom levels.

Best regards
Dieter
 

corwin42

Expert
Licensed User
Longtime User
We should point out, that bulk downloading of OSM Tiles is not desired (see OSM Tile usage policy). Tiles should only be downloaded if they are needed.:rolleyes:

Thanks for the link to this policy. It changed a lot in the last weeks. The part that bulk downloading of zoomlevels 17 and 18 is prohibited is completely new.

The idea of PDA TileManager was mainly to download all tiles along a GPX route so it would be possible to navigate along this route with the help of a map without the need of being online. Normally it downloads only new tiles that are not already cached so I think that overall my program reduces the load on the tile servers.

I like to travel at spontaneously planned routes. For such cases it would not be economically to download all eventually needed map tiles at the required higher zoom levels.

I completely agree here. Bulk downloading tiles should be used very carefully.
 

nm7s9

Member
Licensed User
Thanks for the app Dieter,

I gave it a run on my Garmin Nuvifone M10 this afternoon. It worked well. (M10 is WVGA)

I do quite a bit of mapping on OSM and it is very useful for me to have up-to-date tiles. There are a few of us in Canberra Australia who like to have the OSM data up to date to within a few days and when mapping in a new suburb it is nice to see if someone else has already beaten me to survey a newly finished road.

I did find that your pointer, on the screen appears to be consistantly about 230 meters almost due north of the correct position when used in Canberra Australia.

Other features that would be useful for OSM mapping would be
1) Track logging - at a consistant rate (down to one point er second)
2) Showing the path taken so far in a bright colour on the screen, so that I don't resurvey a road.
3) Centering the pointer (this may require a few surrounding tiles) but they'll probably be needed at some time anyway.

At a slow driving speed, I don't think that this use of the app would create too much load on the tile server.
 
Last edited:

DieterR

Member
Licensed User
Longtime User
I did find that your pointer, on the screen appears to be consistantly about 230 meters almost due north of the correct position when used in Canberra Australia.

Your are right. I simulated Canberra coordinates and was wondering.:sign0148: At home the program works very precisely. When driving on a street, the pointer is always over the street in the map. I belive, there must be a problem with the south hemisphere data. I need some time to analyse it.

At a slow driving speed, I don't think that this use of the app would create too much load on the tile server.

I think the server load will also limited by the low download transfer rate when mobile.

Best regards
Dieter
 

mjcoon

Well-Known Member
Licensed User
... e.g. a nice feature would be a seamless scrolling from one map tile to the next. In the present version only one tile is shown and the change is very 'skippy'.

I've recently written a program that I am happy to "throw into the mix". It seamlessly scrolls from one tile to another.

But it isn't dealing with OSM tiles. Years ago I bought a PPC GPS/mapping product called GPSDash. (It seems not to be still under development but is available presumably still as shareware.)

This program comes with a PC program that can split a large bitmap into 256x256 pixel tiles, which it names 0000.mti, 0001.mti, 0002.mti along the top edge and 0100.mti, 0200.mti, and so forth, down the left edge. There is also an index file which records the original pixel size and any geo-referencing coordinates that have been applied, again using this same program.

So my program keeps a 3x3 square of nine of these tiles and loads fresh tiles as needed during scrolling. The scrolling can be done by dragging the stylus or, on a tile-by-tile basis, using scrollbars.

I don't suggest that it is a polished product; I wrote it just for learning purposes, but some of the code might be useful...

Mike.
 

Attachments

  • MapViewer.zip
    5.4 KB · Views: 333

mjcoon

Well-Known Member
Licensed User
Now, I am going to implement the OSM tiles 'App' into my outdoor GPS tool. ...

Hi Dieter, you may already have spotted this, but playing with your code (trying to do smooth scroll as discussed) I noticed that the Sub
B4X:
Sub LimitY (Y )
   Return Max(-180.0, Min(180.0, Y))
End Sub
does not take into account that latitude can be no greater than 90 degrees at the poles!

Best wishes, Mike.
 

DieterR

Member
Licensed User
Longtime User
Hi Mike,

sorry for my very late answer.:(
You are right!
I already changed the code. The correct limitation is as following:
B4X:
Sub LimitY (Y)
   Return Max(-85.05, Min(85.05,Y))
End Sub
These values are necessary due to the behaviour of the mathematical functions. For more infos, please see the OSM Wiki.

Best regards
DieterR
 

DieterR

Member
Licensed User
Longtime User
Added improved program sample

Hi,

I just uploaded an improved version of my OSM Tile Viewer sample app. The major problem of the previous version was, that the GPS position was only correct shown in case of higher zoom levels (>10). The reason was the very simple algorithm I used. Now I spend a few hours in mathematics to find a better solution. :D

I think, the new version is more than sufficient precise for mobile applications. It shows the GPS position correct within a few pixels for all zoom levels: 0 - the whole earth, up into the range of the GPS precision.
A further major improvement regards to different screen size resolutions. The map will not longer be stretched when other screens than 320x240 are used.

It should be easy for you to add further map tiles side by side to fill larger screens ...

DieterR
 

wm.chatman

Well-Known Member
Licensed User
Longtime User
:) Hi DieterR

thank you for your OSM Tile Viewer sample app. The App works great on my HTC HD, with the internal GPS.

Questions please.
Would it be to much trouble to center the GPS Position on the Map?
I would like to use the external Bluetooth Device. The Com Port on the HTC would be Com8. Would I need to change the OSM Tiles Config Settings, in order to use my external Bluetooth Device.
Please Advice.

Edit: I tested your App in the Field on my HTC Unit. Your right, it's off a few Pixels. When Zoom to 14 or 15 GPS Position is a few Pixel's past the real time Position.
As with the external Com8 matter, I have not got this to work yet. Please Advice how this can be done.

Edit: OK. Made a Change in the OSM Tiles Config. Sys.
GPSAuto=false
#COM8 and Baud if Auto=no
COM8
Baud4800
now work's with external Bluetooth Device on HTC.

Another Question please. I would like to use a Label to show Lat / Lon.

Code:
form1.FDrawString("GPS: "& Format(GpsData.lat,"n4") & " : " & Format(GpsData.lon,"n4"),10,2,38,200,56,cBlack)
Label9.Text.FDrawString("GPS: "& Format(GpsData.lat,"n4") & " : " & Format(GpsData.lon,"n4"),10,2,38,200,56,cBlack)
this does not work for me, what would be the correct code for using a label?

Thank you for your Time and Help.

Best regards.

PS> Keep up the great Work on this APP, it's just Great. :)

William
 
Last edited:

DieterR

Member
Licensed User
Longtime User
Hi William,

Questions please.
Would it be to much trouble to center the GPS Position on the Map?
PS> Keep up the great Work on this APP, it's just Great. :)
I have already much trouble with this issue. Please, google to "KDR GPS MAP". You can download my "ready to use App" with many features from Heise or my HP. I spend a few hundred hours in it. It works fine for higher zoom levels. But it is a very hard work to improve the precision for lower zoon levels. It requires a very complex computation because of seamless zoom and map moving in combination with the mercator projection of the map tiles.:cool:

Another Question please. I would like to use a Label to show Lat / Lon.
The text made by FDrawString might be immediately erased by the function "form1.FErase(....)" when the GPS cursor is refreshed. Either limit the FErase area or create a smal panel and add a label on it.
 

wm.chatman

Well-Known Member
Licensed User
Longtime User
Hi DieterR

I have downloaded your KDR GPS Map, and tested this on my HTC in the Field.
I noticed that you solved your Zoom and Pixel Problem, and it’s much better now.
Would you maybe be willing to correct the Zoom and Pixel Matter, in your OSM Tile Viewer sample App.?
 

DieterR

Member
Licensed User
Longtime User
Hi William,

I noticed that you solved your Zoom and Pixel Problem, and it’s much better now.

No, these are two very different apps.
In my "KDR GPS Map" the GPS position will not be shown at zoom levels < 8 because it would have a big deviation. The deviation is caused by the linear algorithm used. It does not care the non linear distances within a mercator map. That algorithm works fast and is sufficient precise for zoom levels as used for hiking and biking (12 - 16). In case of proper GPS signals (no buildings, no trees) you can see wheater you are at the left or right side of a street.:)

I optimized the OSM Tile Viewer to show the GPS position at all zoom levels. I checked it with several significant points in the whole earth view (zoom level 0) and others. (For such verifications I am using a GPS simulator, not the real outdoor site.:cool:).

Would you maybe be willing to correct the Zoom and Pixel Matter, in your OSM Tile Viewer sample App.?

Not yet, because the problem is not solved.
Let me try to explain it:
In my map app there are 2 x 9 map tiles in an intermediate layer to assemble the moveable map picture (map background, map foreground, routes and waypoints ...). An area of this intermediate layer is "zoomed" to the screen by using the ImageLib.dll. The GPS cursor is drawn directly at the screen foreground layer because it works very fast. For a correct positioning the map coordinates of the intermediate layer have to be transfered via the "zoom mechanism" to the screen. This computation is relatively complex and slow.:BangHead:

  1. An easy solution would be to forget the GPS cursor (and direction arrow) and draw only a GPS track in the intermediate layer. The ImageLib is fast enaugh to refresh the screen every second.
  2. For my map app I am thinking about a solution where the new map viewer algorithm is only applied at lower zoom levels.

--------------------------
Others: In my opinion OSM maps are the best for mobile devices. Why should we not start a new open source project? Later it may be continued with android:icon_clap:

Best regards
DieterR
 
Top