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

warwound

Expert
Licensed User
Longtime User
For anyone that is having problems relating to hardware acceleration and force closes (see my last post in this thread), please take a look at this page: Issue 303 - osmdroid - Support hardware acceleration in MyLocationOverlay and ScaleOverlay - OpenStreetMap-Tools for Android - Google Project Hosting

It's a reported issue on the official OSMDroid project page.

It is only an issue if your app has android:targetSdkVersion="14" or higher.

So if you have modified your B4A project's manifest file and set a target SDK of 14 or higher then you will likely see this problem.

You'll also see this problem on any ICS device where in Settings > Developer options, Force GPU Rendering is enabled.

Until the OSMDroid project comes up with a proper solution the only workaround i can suggest is to NOT set a targetSdkVersion of 14 or higher in your project's manifest file.

But note - if a user checks the option Force GPU Rendering then your app will force close and there is no way for your app to override that user setting.

Martin.
 

aptinis7

Member
Licensed User
Longtime User
can i use osmdroid for google places ?

Nice job!! I have a question? Can i use Autocomplete text for google places using osmdroid lib ?
 

warwound

Expert
Licensed User
Longtime User
Nice job!! I have a question? Can i use Autocomplete text for google places using osmdroid lib ?

Well your problem is that Google state:

If your application displays Places API data on a map, that map must be provided by Google.

https://developers.google.com/places/documentation/

So technically, you are not allowed to display any data from the Places API on an OSMDroid map.

Displaying Places API data on a Google Maps API map in a WebView is acceptable of course.

Martin.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Until the OSMDroid project comes up with a proper solution the only workaround i can suggest is to NOT set a targetSdkVersion of 14 or higher in your project's manifest file.
Another option is to add this line:
B4X:
SetApplicationAttribute(android:hardwareAccelerated, "false")
This will allow you to set targetSdkVersion to 14.
 

warwound

Expert
Licensed User
Longtime User
Another option is to add this line:
B4X:
SetApplicationAttribute(android:hardwareAccelerated, "false")
This will allow you to set targetSdkVersion to 14.

True, but i remember reading somewhere that if an ICS device user enables the Force GPU rendering setting then that setting will take preference over any manifest or other application specific setting.

The Force GPU Rendering option sounds like a 'magic' setting...
Imagine:
Just check this box and all your apps will run faster due to hardware acceleration!

Users will enable it not realising that it will crash in-compatible apps.

Martin.
 
Last edited:

cirollo

Active Member
Licensed User
Longtime User
problems compiling

Hi! following the example of Avoid a Crime application, downloaded the library and example but when compiling I get this error:

Compiling code. 0.12
Compiling layouts code. 0.03
Generating R file. 0.00
Compiling generated Java code. Error
javac 1.6.0_26
src\avoid\a\crime\main.java:54: cannot find symbol
symbol : variable sharedProcessBA
location: class anywheresoftware.b4a.BA
processBA.sharedProcessBA.activityBA = null;
^
1 error

what is?? b4a 2.02
 

Agnetha

Member
Licensed User
Longtime User
Error removing markers

Hi!

I need to remove all markers from the markersballoon overlay.
When i remove a focused marker the next marker gets the focus.
When i remove the last marker, who is focused, the app crashes.
 

warwound

Expert
Licensed User
Longtime User
Hi.

Can you test the attached updated library files and let me know if the bug is now fixed?

If it's fixed i'll get the bug fixed version uploaded asap.

Thanks.

Martin.
 
Last edited:

metrick

Active Member
Licensed User
Longtime User
Is it possible to add three or four movable marker point? Can you show some sample code. Thanks in advance.
 

warwound

Expert
Licensed User
Longtime User
Hi.

Believe it or not this is nowhere near as easy as it sounds...
In theory you'd add some markers to an overlay layer and change their position by setting a new GeoPoint or new latitude and longitude and it 'would just work'.

BUT it doesn't!

Internally the library uses a GeoPoint for each marker's position and the GeoPoint class simply never had setter methods to modify any of it's properties, the original Android source calls a GeoPoint an Immutable class.

So you can construct a GeoPoint with title, description and position but not change of those properties afterwards - so no way to change the position of a marker.

If you have time you could read this thread where i discussed it on the Google Groups: https://groups.google.com/forum/?hl=en&fromgroups=#!topic/osmdroid/9TQPw33NDBM.
(The discussion relates to the original Android library but applies to the B4A library).

A solution i suggested was to use a SimpleLocationOverlay for each marker - the SimpleLocationOverlay has methods to both set and get the marker position BUT can only display a single marker per overlay layer.
That would leave you with the pegman icon for every marker - probably not what you want but you could change the Objects\res\drawable-nodpi\person.png icon to suit.

I always intended to create my own overlay layer where a marker's position could be updated, but like many things i've just not had the time to do so.

Martin.
 

warwound

Expert
Licensed User
Longtime User
A guess would be you have latitude and longitude the wrong way around?

If not you'd best export and upload your project and I'll take a look.

Martin.
 

GaNdAlF89

Active Member
Licensed User
Longtime User
The same coordinates work correctly with google maps...
Code is the same in the example, I modified only this line
B4X:
MapCenter.Initialize(52.75192, 0.40505)
I replaced only this coordinates..There is any setting that I have to modify??
 

warwound

Expert
Licensed User
Longtime User
That should be all you need to change - you'll have to export and upload your non working project so I can take a look.

Martin.
 

GaNdAlF89

Active Member
Licensed User
Longtime User
The problem is that the coordinates that I pass to function are string type...How can I cast a string to a double?
 

warwound

Expert
Licensed User
Longtime User
Hi.

You need to Dim two Double type variables and assign the String types to the Double variables - B4A should(!!) correctly convert the String values to Double values:

B4X:
Dim Lat, Lng As Double
Lat=LatStringValue
Lng=LngStringValue
MapCenter.Initialize(Lat, Lng)

If that fails - your Strings may have white space for example - use the String Trim method to remove whitespace.

Martin.
 
Top