B4A Library OSMDroid - MapView for B4A

GaNdAlF89

Active Member
Licensed User
Longtime User
How can I display a point of location I passed with coordinates? with a marker?
Can you post an example code for this? thanks
 

GaNdAlF89

Active Member
Licensed User
Longtime User
I try this
B4X:
Sub Process_Globals

   Dim MapCenter As GeoPoint
   
   Dim MapMarker As Marker
   
   Dim ZoomLevel As Int
   
End Sub

Sub Globals
    
     Dim MyMapView As MapView
     
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   MyMapView.Initialize("")
   
   Activity.AddView(MyMapView, 0, 170, 100%x, 100%y-170)
   
   MyMapView.Visible = False
   MyMapView.SetZoomEnabled(True)
   MyMapView.SetMultiTouchEnabled(True)
   
   Dim dlat, dlong As Double
   dlat = myLatitude
   dlong = myLongitude
   
   MapCenter.Initialize(dlat, dlong)
   
   MapMarker.Initialize3("MapMarker","",MapCenter,Null)
   
   Dim Markers As List
   Dim ovlMarkers As MarkersOverlay
   
   Markers.Initialize
   Markers.Add(MapMarker)
   
   ovlMarkers.Initialize(MyMapView,"")
   ovlMarkers.AddMarkers(Markers)
   
   MyMapView.AddOverlay(ovlMarkers)
   
   ZoomLevel = 18
   
   MyMapView.Zoom = ZoomLevel
   MyMapView.SetCenter3(MapCenter)
   MyMapView.SetTileSource("OSMPublicTransport")
   
End Sub

but I don't see any marker...please help me!!
 

warwound

Expert
Licensed User
Longtime User
You have not set a custom icon for your marker so the library will try to use the default icon - have you copied the resouces from the library_default_resources folder (in the library download) to your B4A project?

You need to check if Objects\res\drawable-nodpi\marker_default.png exists.

If that isn't the problem, try dragging the map a little - does the marker now appear?

Martin.
 

Stulish

Active Member
Licensed User
Longtime User
hi,

I have been looking at a offline chart app for android to be used at sea (no internet) and have found www.openseamap.org this site uses the open street map and has created sea maps, is it possible to download their charts and use them with OSMDroid?

thanks

stu
 

Stulish

Active Member
Licensed User
Longtime User
thanks I will have a play
 

GaNdAlF89

Active Member
Licensed User
Longtime User
yes, the problem was the icon, I forgot to copy it!! Thanks..
 

mortenplaya

Member
Licensed User
Longtime User
Tile Map Service layer support in OSMdroid

Hi OSMdroid developers,
Thanks for a fantastic product!
It would be nice to have TMS(Tile Map Service)layer support in the OSMdroid library. This will give instant access to Open GIS server implementation of the TMS specification like:

* TileCache
* GeoWebCache
* MapProxy

The TMS specification is similar to Slippy Map specification used by OpenStreetMap, except y axis:
- TMS count y tiles from bottom to top (origin at bottom left corner).
- Slippy Map(OpenStreetMap) count tiles from top to bottom.

Example of custom URL template:
"http://servername/contextpath/service/tms/1.0.0/layername/z/x/y.formatExtension"

Conversion to TMS is done with:
y = (int)(Math.pow(2, zoomLevel) - y - 1);

Useful links to android java forums;
OSMdroid-Plus implementation of TMS
TMS patch for OSMdroid


Best regards
Morten

This post might belongs to a new Thread under "Wishlist"
 

metrick

Active Member
Licensed User
Longtime User
Is it possible to rotate map and change the map to SATELLITE mode?
 
Last edited:

warwound

Expert
Licensed User
Longtime User

Hi.

That all sounds quite straightforward to implement - just leaves the question of how to implement...

OSMDroid currently has the TilesOverlay and XYTileSource objects.
Both of these objects use slippy map tilenames, so one or both are suitable for updates to enable TMS support.

What's best - 2 new objects similar to TilesOverlay and XYTileSource that use TMS tilenaming OR update the existing 2 objects with new Initialize methods to accept TMS tileserver URLs instead of slippy map tileserver URLs?

I think option 2 - update the existing objects with new Initialize methods.
That'll require some modifications to the java source based on the native Android OSMDroid patches that you posted links to, so i'll not promise to get that done immediately.
Work first and then some play, so i'll try and get the updates done over the weekend.

Martin.
 

warwound

Expert
Licensed User
Longtime User
Is it possible to rotate map and change the map to SATELLITE mode?

Hi there.

By rotate you mean by a variable number of degrees, like the Android Maps app?
No that's not possible.
I did read a while back that others were trying to do this, they never succeeded as it was far from a simple task.

As for satellite tiles, there's the built in MapquestAerial TileSource but that displays very limited zoom levels unless you are in the USA.
Outside of the USA it zooms only to a relatively low maximum zoom level.
Have a read of this thread for some more info:http://www.b4x.com/forum/basic4andr...-osmdroid-mapview-b4a-tutorial.html#post92646.

If you're outside of the USA the only other solution is to find an alternative satellite tileserver that you are allowed access to, and use XYTileSource to add that tileserver to your MapView.

Martin.
 

warwound

Expert
Licensed User
Longtime User
It would be nice to have TMS(Tile Map Service)layer support in the OSMdroid library.

Right that was quicker to do than i thought!
Attached is an updated version of OSMDroid, the XYTileSource object now has a new Property named TMSMode:

Get or Set whether Tile Map Service (TMS) mode is enabled or not.
By default TMS mode is NOT enabled.

Take a look at the XYTileSource tutorial pages: http://www.b4x.com/forum/basic4andr...smdroid-mapview-b4a-tutorial-6.html#post96437 and http://www.b4x.com/forum/basic4andr...smdroid-mapview-b4a-tutorial-6.html#post99258

Can you give this update a test and report back whether it works or not?
(I have no access to a TMS server).

Just set the TMSMode property of an instance of XYTileSource to True and it should adjust the tile name requests as desired.

If it works then i'll look at updating the TilesOverlay too - could you test that too?

Thanks.

Martin.
 
Last edited:

mortenplaya

Member
Licensed User
Longtime User
Hi Martin
Thanks for quick response! Amazing - I'm used to “OpenLayers software” where I have to wait for annual updates.
I will dive into the stuff this weekend and test it. I will give my feedback when I'm done.

Thanks
Morten
 

mortenplaya

Member
Licensed User
Longtime User
TMS support in OSMDroid

Hi Martin,
The TMS support in OSMDroid is working fine:sign0098:.

Here is an example of my test configuration:
B4X:
MapCenter.Initialize(63.43198, 10.3975)
...
MyXYTileSource.Initialize("myTMStilesource", 14, 17, 256, ".png", "http://mapping.no/TMStest/")
MyXYTileSource.TMSMode=True

MyXYTileSource object has to be intialised before setting TMSMode=True.

I'm looking forward to test the TilesOverlay functionality.

Setting up a simple TMS service is relatively easy. Check this website for more info:
Setting up TMS

Tools for making standard TMS tiles:

Gdal2tiles
MapTiler

To all hobby map makers. Just remember that the maps are the intellectual property covered by international copyright laws.

Thanks,
Morten
 

warwound

Expert
Licensed User
Longtime User
Great!

Here's another alpha update with TMS support enabled for the TilesOverlay object:

TilesOverlay
Properties:
  • DataConnectionEnabled As Boolean
    Get or Set whether this TilesOverlay will use the device's data connection.
  • LoadingBackgroundColor As Int
    Get or Set the background color displayed while waiting for a tile to be downloaded.
    Setting a value of Colors.TRANSPARENT will disable the display of any background color.
    The default value is Colors.TRANSPARENT, no background color is displayed.
  • LoadingLineColor As Int
    Get or Set the line color used to separate the background color drawn while waiting a tile to be downloaded.
    The line color will only be drawn if the background color is NOT set to transparent.
    The default value is Colors.rgb(200, 192, 192).
Methods:
  • Initialize (Name As String, MinZoomLevel As Int, MaxZoomLevel As Int, TileSize As Int, TileFilenameEnding As String, BaseUrl As String)
    Initialize the TilesOverlay, the TileSource must implement the Slippy map tile naming convention.
  • Initialize2 (Name As String, MinZoomLevel As Int, MaxZoomLevel As Int, TileSize As Int, TileFilenameEnding As String, BaseUrls As String())
    Initialize the TilesOverlay, the TileSource must implement the Slippy map tile naming convention.
    An Array of Strings is passed for the BaseUrls parameter.
  • Initialize3 (Name As String, MinZoomLevel As Int, MaxZoomLevel As Int, TileSize As Int, TileFilenameEnding As String, BaseUrl As String)
    Initialize the TilesOverlay, the TileSource must implement the TileMapService (TMS) map tile naming convention.
  • Initialize4 (Name As String, MinZoomLevel As Int, MaxZoomLevel As Int, TileSize As Int, TileFilenameEnding As String, BaseUrls As String())
    Initialize the TilesOverlay, the TileSource must implement the TileMapService (TMS) map tile naming convention.
    An Array of Strings is passed for the BaseUrls parameter.
  • IsInitialized As Boolean

As you can see you need to use either the Initialize3 or Initialize4 methods to enabled TMS support for the TilesOverlay.

Thanks.

Martin.
 

schimanski

Well-Known Member
Licensed User
Longtime User
Center the Icon of a marker

Hello warwound! Thanks for this wonderful library. It runs perfect in my application..:sign0098: Bevor I used my tilemapviewer, which had many problems....

http://www.b4x.com/forum/basic4android-share-your-creations/7323-openstreetmap-tilemapviewer-4.html#post45387

I have only one problem, perhaps there is a solution for that:

I get some gps-data from a server each second and shows this position in the center of the map. Now, I want to show my own gps-position in the same map. When I use MyLocationOverlay, there is a problem because I need the gps-data from the gps-library to make some calculation and it seems, that it is not possible to get gps-data from the gps-lib and at the same time using MyLocationOverlay. The app will hand up...
So, I have used the MarkerOverlay to show my own position with a marker in the map, which is updated every second. That runs fine, but the gps-position of a marker is always shown at the bottem of the markers icon. Now it is not possible to use an rotating arrow wich shows the bearing like MyLocationOverlay does this. Is there a way to center the marker on the gps-position?

Thanks for your great work....
 

mortenplaya

Member
Licensed User
Longtime User
Test of TMS and TilesOverlay functionality

Hi Martin,
I have been testing the TilesOverlay. My test map overlay was matching the OSMStreetMap background map perfectly.
There is just one thing that I have noticed. When zooming the map I have to pan the map to refresh/redraw the tiles overlay. I have been running the test on the android emulator platform 2.2. I have also been testing the solution on my Sony Ericsson Xperia Active moboile android version 2.3.3. The bakground map (OpenStreetMap) draws smoothly and I'm using a fast 90 Mbit Internet connection. I will try to do the test again using a GeowebCache server to see if it makes any difference.

Here is my simple test solution
B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim MapView1 As MapView
   Dim TilesOverlay1 As TilesOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If File.ExternalWritable=False Then
      '   OSMDroid requires the use of external storage to cache tiles
      '   if no external storage is available then the MapView will display no tiles
      Log("WARNING NO EXTERNAL STORAGE AVAILABLE")
   End If
   
   MapView1.Initialize("")
   MapView1.SetMultiTouchEnabled(True)
   MapView1.SetZoomEnabled(True)
   MapView1.Zoom=14
   MapView1.SetCenter(63.43198, 10.3975)
   Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
   
   ' my tile overlay with zoom level from 14 to 17
   TilesOverlay1.Initialize3("myTileOverlay", 14, 17, 256, ".png", "http://mapping.no/TMStest/")
   
   MapView1.AddOverlay(TilesOverlay1)
   
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Anyway, thanks for a great library! :sign0188:

Best regards
Morten
 

warwound

Expert
Licensed User
Longtime User
@schimanski

The MyLocationOverlay object has various methods that might do all that you require - so hopefully there's no need to enable GPS features as well as MyLocationOverlay.
Here's the reference for MyLocationOverlay:

MyLocationOverlay
Events:
  • FollowLocationAutoDisabled
  • LocationChanged(NewLocation As Location, IsFirstFix As Boolean)
  • ProviderChanged(Provider As String, Enabled As Boolean)
Properties:
  • CompassEnabled As Boolean
    Get or Set whether the compass is enabled.
    Default value is False.
  • DrawAccuracyEnabled As Boolean
    Get or Set whether the DrawAccuracy circle is drawn around the Person icon.
    Default value is True.
  • FollowLocationEnabled As Boolean
    Get or Set whether FollowLocation is enabled.
    If FollowLocation is enabled then the map will automatically center itself on the last GPS fix.
    Default value is False.
  • LastFix As LocationWrapper
    Get the last GPS fix as a Location object.
  • LocationUpdateMinDistance As Float
    Get or Set the minimum distance (in meters) change that should be considered a new GPS fix.
    Default value is 0.
  • LocationUpdateMinTime As Long
    Get or Set the minimum time (in milliseconds) between GPS fixes that should treat the last fix as a new fix.
    Default value is 0.
  • MyLocationEnabled As Boolean
    Get or Set whether the MyLocationOverlay should listen for GPS fixes.
    Default value is False.
Methods:
  • Initialize (aMapView As MapView, EventName As String)
    Initialize the MyLocationOverlay.
  • IsInitialized As Boolean
  • SetCompassCenter (X As Float, Y As Float)
    Set the point at which the compass should be drawn within the MapView.
    Default value is (35, 35).

You need to include the GPS library so that you can work with the Location object, it looks as though the only GPS library feature not available with MyLocationOverlay is accessing the GPSSatellite objects.
What features of the GPS library are you using that are not available in MyLocationOverlay?

@Morten

Can you try running the TilesOverlay demo on the same devices and let me know if the (slippy) TilesOverlay correctly redraws on zoom change?
I've just run that demo on my 1GHz Huawei Ascend (ICS) and the TilesOverlay correctly displays new tiles when the zoom level changes.
On my 600Mhz ZTE Blade (Gingerbread) the TilesOverlay displays correctly on zoom change if the tiles are already on the device - in the tile cache.
However if the tiles are not cached then the TilesOverlay will only correctly redraw IF the required tiles download within a reasonable amount of time.
The demo uses tiles from openseamap.org which is a relatively slow server - if a new tile request takes too long to return then the TilesOverlay does not display correctly, otherwise it works fine.

How fast is your tile server at mapping.no (is it serving from your 90Mb/s home broadband or is it on the internet)?
Let some overlay tiles download into the tile cache and then try zooming in and out on the same area - does the TilesOverlay now correctly display?

Martin.
 

schimanski

Well-Known Member
Licensed User
Longtime User
Hello warwound! Thanks for your efforst!

I use the data of the gps-lib in a service because, I need the gps-data not only in my mapview-activity. There are some other activities, which needs the gps-data. Also I need the satellites in use, the speed and the altitude, so I think, that I can not miss the gps-library for my application. The only thing I need is to show an icon on a gps-position, which is centered on the position. Than I can show my own icon with an arrow for the bearing....:sign0148:

Thanks for an answer and greetings from germany..
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…