B4A Library OSMDroid - MapView for B4A

Here we have my latest library - OSMDroid provides a MapView for B4A.

More info on the original (native Android) OSMDroid project can be found here: osmdroid - OpenStreetMap-Tools for Android - Google Project Hosting.

Library reference is no longer included in this post due to limits on the number of characters allowed in a single post.

I have created some tutorials to show basic usage of the library and will update this thread with a link to them as soon as i have them all uploaded.

** Your attention is drawn to the included file Apache License Version 2.0.txt, which is a copy of the Apache License Version 2.0 under which the native Android OSMDroid library is released **

Martin.
 

Attachments

  • OSMDroid_3_0_8_v3.60.zip
    361.9 KB · Views: 4,200
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Your efforts finally lead to fruition! :icon_clap::icon_clap::icon_clap:
Nice work.
I'm just a bit hazy on LGPL. The library itself can now be distributed (as it is not a modified source?) and any app using it can also be distributed under any license.

Anyway, this was an immense work :sign0188::sign0188::sign0188:
 

bluedude

Well-Known Member
Licensed User
Longtime User
Offline mode

Am I correct if I conclude that the cache is used (SD card) for offline mode? So if you have been somewhere there is a cache available for that location?

Great work on the library!
 

warwound

Expert
Licensed User
Longtime User
Am I correct if I conclude that the cache is used (SD card) for offline mode? So if you have been somewhere there is a cache available for that location?

Great work on the library!

Yes if you look on the device SD card for a folder named osmdroid that is the cache folder.

It's shared by all (installed) applications that use an OSMDroid based map - whether using this library or the native Android library.

Inside the cache folder is a folder named tiles and inside that are folders named after the tilesource (Mapnik for example).
Each tilesource folder contains all cached tiles for that tilesource named and structured according to the Sllippy map tile naming convention.

That makes it possible to use your own custom tiles if you have access to any.

And you can even create a tileset from a panorama and use the MapView as a panorama viewer - something that's been discussed recently on the forum.

I'm working on an example of how to use offline tiles and will hopefully have that uploaded later or tomorrow.

Martin.
 

warwound

Expert
Licensed User
Longtime User
I'm just a bit hazy on LGPL. The library itself can now be distributed (as it is not a modified source?) and any app using it can also be distributed under any license.

Hmmm i shall have to look into this - i was under the impression that as long as i made available the source code for any modifications to the original code that i would be ok to distribute such modifications.

I'll post again as i find out more about the technicalities of LGPL.

Martin.
 

warwound

Expert
Licensed User
Longtime User
OSMDroid updated to version 1.01

This is a minor update that adds supports for using a Cloudmade API key.

If are are not going to use a Cloudmade API key there is no need to update your library files.

An example of using a Cloudmade API key can be found here: http://www.b4x.com/forum/basic4andr...smdroid-mapview-b4a-tutorial-2.html#post92864.

Latest version of the library is attached to the first post in this thread.

You do NOT need to update the native_android_libraries.zip files, just the B4A library files.

Martin.
 

barx

Well-Known Member
Licensed User
Longtime User
Looks awsome. :sign0142::sign0098:
 

warwound

Expert
Licensed User
Longtime User
I have now updated the attachment in the first post which contains the additional native Android libraries.

Users of versions of B4A prior to the current 1.8 will need the two dummy XML files that i have added to that attachment - now named native_android_libraries_20120328.zip.

The readme.txt file in that attachment explains what is required:

If you are using a version of Basic4Android that is older than 1.8 then you must also copy NativeOSMDroid.xml and slf4j-android-1.5.8.xml to your B4A additional libraries folder.

Note that you will also need to reference NativeOSMDroid and slf4j-android-1.5.8 in your projects by checking the boxes in the IDE library list.

If you are using Basic4Android version 1.8 (or a newer version) then you DO NOT need to copy NativeOSMDroid.xml and slf4j-android-1.5.8.xml to your B4A additional libraries folder.

I've attached the 2 extra dummy XML files to this post - if you have already copied the native Android libraries to your B4A additional libraries folder then you can download just these two dummy XML files rather than the entire native_android_libraries_20120328.zip file.

Martin.
 

Attachments

  • dummy_xml_files_only.zip
    446 bytes · Views: 548

warwound

Expert
Licensed User
Longtime User
OSMDroid updated to version 1.02

  • Updated MapView AddOverlay method so an Overlay cannot be added to the MapView more than once.
  • Updated RemoveOverlay and RemoveOverlays methods, if an Overlay is not actually removed from the MapView then the MapView is not invalidated (internally).
  • BoundingBox object now has Initialize and Initialize2 methods:

    Initialize (LatitudeNorth As Double, LongitudeWest As Double, LatitudeSouth As Double, LongitudeEast As Double)

    B4X:
    Dim UKBounds As BoundingBox
    UKBounds.Initialize(58.77, -13.8, 50.49, 3.4)

    Initialize2 (NorthWest As GeoPoint, SouthEast As GeoPoint)

    B4X:
    Dim UKBounds As BoundingBox
    Dim NorthWest, SouthEast As GeoPoint
    NorthWest.Initialize(58.77, -13.8)
    SouthEast.Initialize(50.49, 3.4)
    UKBounds.Initialize2(NorthWest, SouthEast)

    Both those code examples will produce the same result - a BoundingBox that represents (roughly!) the geographical bounds of the UK.

    The MapView FitMapToBoundingBox method can now be used to pan and zoom the map to fully contain the BoundingBox:

    B4X:
    MapView1.FitMapToBoundingBox(UKBounds)

b4a_library_v1_02.zip is attached to the first post in this thread.

Martin.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Adding markers from json

Hi,

I'm parsing a JSON file with long, lat and want to add that to the marker layer.

For some reason I don't seem to be able to do something like:

Dim Markers As List
Markers.Initialize

for i=0 to 10
Dim Marker1 As Marker
Marker1.Initialize("Home sweet home", "bla", 52.75610, 0.39748, Icon)
Markers.add

next
'add markers
ovlMarkers.AddMarkers(Markers)

Cheers,
 

warwound

Expert
Licensed User
Longtime User
Have you created an Icon object?
Try passing Null for the Icon value - a default icon will be used.

Is Markers.add a typo or bad copy/paste?
Markers.add(Marker1) is what's required.

Is ovlMarkers a MarkersOverlay or a MarkersFocusOverlay?
Has it been initialzed?
Has it been added to the MapView?

B4X:
Dim Markers As List
Markers.Initialize

For i=0 to 10
 Dim Marker1 As Marker
 Marker1.Initialize("Home sweet home", "bla", 52.75610, 0.39748, Icon)
 Markers.add(Marker1)
Next

'add markers
ovlMarkers.AddMarkers(Markers)

Posting a ZIP'd project makes answering such a question so much easier.

Martin.
 

bluedude

Well-Known Member
Licensed User
Longtime User
The zip

Hi,

Hereby the zip. Looking for the best way to add lots of markers (from a JSON file) fast.

I have the json processing in place (poi's from a web service).

Cheers,
 

Attachments

  • mapview_markers.zip
    7.3 KB · Views: 826

warwound

Expert
Licensed User
Longtime User
Well this is rather strange...

I added a Log statement to the OSMDroid library and recompiled, the Log simply Logs the Class of the Marker in the List passed to MapView AddMarkers.

B4X:
Log.d("B4A", "Class="+Markers.Get(count).getClass().getName());

I run your project and it Logs:

Class=org.osmdroid.views.overlay.OverlayItem

Your project fails - AddMarkers is expecting a List over OverlayItemWrappers.

I run the example code from the MarkersOverlay example (09 - OverlayMap), and the Logs shows (as expected):

Class=uk.co.martinpearman.b4a.osmdroid.views.overlays.OverlayItemWrapper

So why in your project are the OverlayItemWrappers becoming OverlayItems and causing the ClassCastException???

I commented out your for loop and copied a line from the working example:

B4X:
   Dim Markers As List
   Markers.Initialize

'   For i=0 To 10
'       Dim Marker1 As Marker
'       Marker1.Initialize("Home sweet home", "bla", 52.75610, 0.39748, Icon)
'       Markers.add(Marker1)
'   Next

   Dim Marker2 As Marker
   Marker2.Initialize("Elsewhere", "Downham Market", 52.60801, 0.39047, Null)
   Markers.Add(Marker2)

   'add markers to overlay
   ovlMarkers.AddMarkers(Markers)

Still the Marker in your project is becoming an OverlayItem instead of remaining an OverlayItemWrapper.

The working project open in another window compiling and running on the same version of the library and the same device works perfectly.

All very strange, i shall apply the classical solution - take a break for lunch and come back to my computer with a fresh head.

BBL.

Martin.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Difference

Well there is a difference of course. You initialize Markers with marker1 and marker2 in the end in your original project by using initialize.

However, it seems to me this isn't usable if you need to define maybe 10-30 markers.

Just wondering how to add multiple markers to a list and add it to the overlay.

Cheers,
 
Top