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,218
Last edited:

peacemaker

Expert
Licensed User
Longtime User
What does such error in old v.3.0.8 mean ?
B4X:
** Activity (gamers) Resume **
** Activity (gamers) Pause, UserClosed = true **
** Activity (main) Resume **


java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
    at java.util.ArrayList.get(ArrayList.java:304)
    at uk.co.martinpearman.b4a.osmdroid.views.overlays.DeprecatedItemizedOverlayWithFocus.draw(DeprecatedItemizedOverlayWithFocus.java:166)
    at org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:119)
    at org.osmdroid.views.MapView.dispatchDraw(MapView.java:901)
    at android.view.View.draw(View.java:13680)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
    at android.view.View.draw(View.java:13680)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
    at android.view.View.draw(View.java:13680)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
    at android.view.View.draw(View.java:13680)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
    at android.view.View.draw(View.java:13801)
    at android.widget.FrameLayout.draw(FrameLayout.java:467)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2226)
    at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2593)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2484)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2340)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2142)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4879)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
    at android.view.Choreographer.doCallbacks(Choreographer.java:579)
    at android.view.Choreographer.doFrame(Choreographer.java:548)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:153)
 

DonManfred

Expert
Licensed User
Longtime User
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
You are accessing index 0 (first item) in an empty arraylist
at java.util.ArrayList.get(ArrayList.java:304)
at uk.co.martinpearman.b4a.osmdroid.views.overlays.DeprecatedItemizedOverlayWithFocus.draw(DeprecatedItemizedOverlayWithFocus.java:166)
at org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:119)
 

peacemaker

Expert
Licensed User
Longtime User
:) it's clear, question is about what the list is :)
 

warwound

Expert
Licensed User
Longtime User
What does such error in old v.3.0.8 mean ?
B4X:
** Activity (gamers) Resume **
** Activity (gamers) Pause, UserClosed = true **
** Activity (main) Resume **


java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
    at java.util.ArrayList.get(ArrayList.java:304)
    at uk.co.martinpearman.b4a.osmdroid.views.overlays.DeprecatedItemizedOverlayWithFocus.draw(DeprecatedItemizedOverlayWithFocus.java:166)
    at org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:119)
    at org.osmdroid.views.MapView.dispatchDraw(MapView.java:901)
    at android.view.View.draw(View.java:13680)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
    at android.view.View.draw(View.java:13680)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
    at android.view.View.draw(View.java:13680)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
    at android.view.View.draw(View.java:13680)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
    at android.view.View.draw(View.java:13801)
    at android.widget.FrameLayout.draw(FrameLayout.java:467)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2226)
    at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2593)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2484)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2340)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2142)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4879)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
    at android.view.Choreographer.doCallbacks(Choreographer.java:579)
    at android.view.Choreographer.doFrame(Choreographer.java:548)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:153)

The java class DeprecatedItemizedOverlayWithFocus is the b4a object MarkersFocusOverlay.

What's happening here is that the MarkersFocusOverlay is looking for the last focussed Marker and not finding it.

Have you added Markers to the MarkersFocusOverlay then focussed on one of them - clicked it - and then removed the Marker?

Martin.
 

peacemaker

Expert
Licensed User
Longtime User
Yes, in the loop markers of the gamers are being added to the map, and removed. And added again, as positions are changed...
How better update many markers, each 2 seconds ?

IMHO, lib class should not raise such error - focused marker may be lost any time, even not only in a game. How to avoid this error ?
I use lib version you made me with possibility to consume the events of all overlays or not consume (returning boolean).

Martin, try how it works: https://play.google.com/store/apps/details?id=peacemaker.propilkko
MArkersFocusOverlay is needed for sure, maybe MArkersOverlay is not so needed...
 
Last edited:

warwound

Expert
Licensed User
Longtime User
@peacemaker

Can you try the attached library update?
This update should clear a flag in the library if you remove the focused Marker and prevent the exception.
 

peacemaker

Expert
Licensed User
Longtime User
@peacemaker

Can you try the attached library update?
This update should clear a flag in the library if you remove the focused Marker and prevent the exception.

B4X:
LogCat connected to: 0123456789ABCDEF
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **

java.lang.NoClassDefFoundError: org.slf4j.helpers.SubstituteLoggerFactory
    at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:74)
    at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase.<clinit>(MapTileModuleProviderBase.java:85)
    at uk.co.martinpearman.b4a.osmdroid.views.wrappers.MapViewWrapper.innerInitialize(MapViewWrapper.java:75)
    at anywheresoftware.b4a.objects.ViewWrapper.Initialize(ViewWrapper.java:64)
    at uk.co.martinpearman.b4a.osmdroid.views.wrappers.MapViewWrapper.Initialize(MapViewWrapper.java:63)
    at peacemaker.propilkko.main._activity_create(main.java:452)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at peacemaker.propilkko.main.afterFirstLayout(main.java:98)
    at peacemaker.propilkko.main.access$100(main.java:16)
    at peacemaker.propilkko.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:153)
    at android.app.ActivityThread.main(ActivityThread.java:5297)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)

Will events in new version be returning boolean as before ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Seems, difference is that
B4X:
Sub MarkersFocusOverlay1_Focus(Mark As Marker) As Boolean
and
Sub MarkersOverlay1_Click (Title As String, Description As String, Point As GeoPoint) As Boolean

I would be using MarkersOverlay, if Marker would be available at click, with all the info.
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Will events in new version be returning boolean as before ?

I'm not sure i understand the question...
The OSMDroid version 4.1 library html documentation can be found in the download: http://b4a.martinpearman.co.uk/osmdroid/OSMDroid_library_files_v4.1_20140428.zip
There you can see which events return a boolean value to indicate that they have handled the event.

Meanwhile i've recompiled OSMDroid version 3.0.8 and tested it myself this time - my b4a project compiles with no problems.
So can you again test the attached update?

Martin.
 

Attachments

  • OSMDroid_3_0_8.jar
    374.6 KB · Views: 328

peacemaker

Expert
Licensed User
Longtime User
Meanwhile i've recompiled OSMDroid version 3.0.8 and tested it myself this time - my b4a project compiles with no problems.
So can you again test the attached update?

This time - yes, starting OK, thanks - will test, those error was not so often to re-produce.
 

warwound

Expert
Licensed User
Longtime User
This time - yes, starting OK, thanks - will test, those error was not so often to re-produce.

OK, if you can post again when you're more sure that the original exception is fixed then i'll make the update a proper update and add it to the first post in this thread.

Martin.
 

agus mulyana

Member
Licensed User
Longtime User
Dear all
execuse me, i have compilled OSMDROID example, before i reinstall WIN 7 OS, there is no problem (working properly), but after i reinstalled WIN 7 OS, and i have been using B4A 4.01 core and API 21, the example program getting error, please help me, thank you
 

peacemaker

Expert
Licensed User
Longtime User
Can this error be catched well ? Seems, some devices (it is Android 4.0) do not support OSMDROID.
Occured when try to move the just loaded map.

B4X:
** Activity (main) Resume **
java.lang.UnsupportedOperationException


    at android.view.GLES20Canvas.drawPicture(GLES20Canvas.java:905)
    at uk.co.martinpearman.b4a.osmdroid.views.overlays.MyScaleBarOverlay.draw(MyScaleBarOverlay.java:286)
    at org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:119)
    at org.osmdroid.views.MapView.dispatchDraw(MapView.java:901)
    at android.view.View.getDisplayList(View.java:10452)
    at android.view.ViewGroup.drawChild(ViewGroup.java:2934)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2573)
    at android.view.View.getDisplayList(View.java:10452)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2681)
    at android.view.View.getDisplayList(View.java:10417)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2681)


    at android.view.View.getDisplayList(View.java:10417)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2681)
    at android.view.View.getDisplayList(View.java:10417)
    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:851)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2034)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1748)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2583)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4503)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
    at dalvik.system.NativeStart.main(Native Method)
 

udg

Expert
Licensed User
Longtime User
Hi Martin,

as you may have seen, some days ago I started a thread to collect comments and hints about elements useful to help me decide whether to go with Osmdroid or GMaps since the subject is totally new to me. Sadly, no response so far.
But, since my sixth sense, from the beginning, yelled out "OSMDROID".. here I am.

The reason for this post is because I'm a bit confused about your lib's versions available:
Should I download v. 3.60 based on Osmdroid 3.08 from post #1 (and in that case slf4j 1.58 or 1.61RC)?
Edit: reading here it seems that slf4j is no longer needed (as any other ancillary file)
Or, since I have not any previous code to upgrade, my choice should be v. 4.1 from your site?

My first project would be quite simple: a map showing user's current position along with a few markers to be clicked on in order to show detailed info about each location.
User should be able to zoom in/out while markers are visible.
Markers selected from a remote DB and based on user selection and/or distance from current position.

TIA

Umberto
 
Last edited:

warwound

Expert
Licensed User
Longtime User
@udg

Definitely go for the newer version 4.1, it contains many bug fixes.
Version 3.08 is very old these days.

The examples i have posted are mostly for the syntax used by version 3.08 but don't require much work to make them work in version 4.1.
 

peacemaker

Expert
Licensed User
Longtime User
to help me decide whether to go with Osmdroid or GMaps since the subject is totally new to me. Sadly, no response so far.

I use OSMdroid lib v.3.x in some game, where markers are the main part, represent the gamers and their bases. Tested with qty up to about 100 markers. I have to say that OSM is very "heavy" solution, need lot's of memory, app is slow very often even on modern devices (even with several markers). OutOfMemory error is regular thing, ecpecially on Android 4.0.x.
But no implementing limitations, comparing to Google Maps.
But Google Map v.2 requiring the registration and existing Google Services - works with 500 markers without any speed issues.
 
Top