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:

warwound

Expert
Licensed User
Longtime User
Hi.

The ScaleBarOverlay width is scaled to 1 inch length by querying for the physical DPI of the screen.
If you search the forum for xdpi you'll find examples that show how to get the number of pixels that represent 1 inch by using the Reflection library, and it looks as though the OS library can do this without Reflection.

The ScaleBarOverlay height is the TextSize + LineWidth.
Default TextSize is 12 and default LineWidth is 2.

Martin.
 

Androidsaetabis

Member
Licensed User
Longtime User
Error using MarkersBalloonOverlay and BalloonMarker

B4X:
Dim infoactividad As BalloonMarker 
Dim tirolinasbalon As MarkersBalloonOverlay 
dim tirolinasinfo As List


tirolinasinfo.Initialize 
infoactividad.Initialize("info","info tirolina",latitude,longitude,Null) ' OK
tirolinasinfo.add(infoactividad) ' OK

tirolinasbalon.Initialize(mapa,"ee","") ' error and crash app

tirolinasbalon.AddMarkers(tirolinasinfo) , obv no add

show this error ' ERROR : android.content.res. resources$notfoundException: resource ID #0x0"
solution ? many thanks
 
Last edited:

warwound

Expert
Licensed User
Longtime User
I bet that you haven't copied the markers_balloon_overlay_resources resource files into your project.

Look in the library download and you'll see a folder named 'markers_balloon_overlay_resources'.

2) 'markers_balloon_overlay_resources' contains drawables and an XML layout that are used by the MarkersBalloonOverlay.
If you use MarkersBalloonOverlay then copy these resources to your project's 'Objects\res' folder.

** All files added to your project's Objects folder must be set to READ-ONLY otherwise the B4A compiler will delete them when you compile or clean your project **

Martin.
 

Androidsaetabis

Member
Licensed User
Longtime User
ok

i dont copy res file :BangHead:
i try

many thanks run ok

B4X:
infoactividad.Initialize("info","info tirolina",lat,longi,Null)
tirolinasinfo.add(infoactividad)
tirolinasbalon.Initialize(mapa,"tirolina","balloon_overlay")

tirolinasbalon.AddMarkers(tirolinasinfo)
tirolinasbalon.FocusedMarker =infoactividad


mapa.AddOverlay(tirolinasbalon)


mapa.SetCenter(lat,longi)
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Hello Martin,

You have really done a great job! I have just completed a new function for my "ARTI" project. The user can ask "Where is the nearest [bank] [restaurant] etc.". The software then looks for this information on OSM (using an API) and displays up to 10 markers, using parts of your OSMdroid library!

Just one small comment: the rectangle of the markers is slightly to small. Especially if a long address needs to be shown then a number of characters are shown outside the rectangle. Probably it has to do with the assumed font that you have used for calculating the needed width.
It would be nice if you increased the width (by about 20%) or add a width multiplier.

Best Regards
Rick

Hi.

Sounds like you're using the MarkersFocusOverlay.
The MarkersFocusOverlay info bubble is very unsophisticated, it does not auto size itself to contain large amounts of text.

I'd recommend you switch to the much better MarkersBalloonOverlay where the info bubble correctly sizes itself to the text it contains.
The info bubble is also very customisable - you'll find more info in the tutorial thread.

Martin.
 

warwound

Expert
Licensed User
Longtime User
in MarkersBalloonOverlay BalloonMarker
you can add a URL link to that will have a website?

You can add a thumbnail image or description?

many thanks



Uploaded with ImageShack.us

to



Uploaded with ImageShack.us

Hi.

You should be able to customise the info bubble as you wish, take a look at this post: http://www.b4x.com/forum/basic4andr...smdroid-mapview-b4a-tutorial-5.html#post95877.

You'll need basic skills in using XML to create a custom info bubble layout.

Martin.
 

RichardHirst

Member
Licensed User
Longtime User
Rotate Marker

Hi.

Is it possible to rotate a marker.. Making a GPS flight tracker and would like to set the marker (Icon) to a heading.

Great work :)

Richard
 

warwound

Expert
Licensed User
Longtime User
Hi.

No there's no built in methods to rotate an icon.
It's been asked a few times before and the best solution seems to be to rotate the icon in B4A and then set it as a Marker icon.

Martin.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Hi.
No there's no built in methods to rotate an icon.
Martin.

I implemented this feature by creating eight icons: North, Northeast, East, Southeast, South, Southwest, West, Northwest.

I choose an icon for a marker by using the icon with the lowest absolute value of the difference between the icon's bearing and the reported GPS bearing.

I find that, in general, this is accurate enough – it does show me driving off the road sometimes though :)

Barry.
 
Last edited:

warwound

Expert
Licensed User
Longtime User
OSMDroid updated to version 3.50

With version 3.50, the default drawable resources used by the library are now contained within the library .jar file.
Previous versions required that you copy the contents of the folder library_default_resources/res/drawable-nodpi to your project's Objects/res/drawable-nodpi folder.
This is longer required, the library download no longer contains the folder 'library_default_resources/res/drawable-nodpi'.

If you use MarkersBalloonOverlay in your project then you will still need to copy the contents of the folder markers_balloon_overlay_resources to your project's Objects/res folder.

I have also changed the filenames of the library files.
Previously the library consisted of OSMDroid.jar and OSMDroid.xml, these library files are now named OSMDroid_3_0_8.jar and OSMDroid_3_0_8.xml.
So if you update to version 3.50 please delete both OSMDroid.jar and OSMDroid.xml from your B4A additional libraries folder.

These changes are in preparation for the release of a new version which will incorporate the functionality of the OSMBonusPack.
OSMBonusPack adds support for Geocoding/Reverse geocoding, Directions, Points of Interest and info-bubbles.
(We already have geocoding and info-bubbles within B4A so the new features here will be the 'get directions' and 'get points of interest' features, check out the link above for more info).

Finally there will be a new version of the library that will be based on the very latest native Android OSMDroid version 3.0.9 source code.
Version 3.0.9 includes many bugs fixes which have been made since i originally compiled the B4A library using the version 3.0.8 source code.
There's too many changes from version 3.0.8 to 3.0.9 for me to simply change the source code and re-compile, as i made various changes to the 3.0.8 source and kept no record of what changes i made.
So creating a new B4A library based on version 3.0.9 means starting from scratch.
This is good news though as it will enable me to get rid of some clutter and add new features - the B4A library based on version 3.0.9 will contain more than a few minor syntax changes - it will not be a drop-in replacement for version 3.0.8.

Anyway i can go into more detail when the version 3.0.9 B4A library is ready for testing.

Version 3.50 of OSMDroid_3_0_8 is attached to the first post in this thread.

Martin.
 

schimanski

Well-Known Member
Licensed User
Longtime User
MarkersBalloonOverlay - open the title-Box

I use the following code to add different Markers with changing positions.
Everytime, when a marker gets a new geoposition, I remove it and draw it new with addmarkers. That runs very fine. The problem I have is, that when the Title-Box is open, it will close by drawing the marker with the new position. Is there a way to hold the Title-Box open or to open it by code?

B4X:
....
Dim MarkersBalloonOverlay1 As MarkersBalloonOverlay
...
MarkersBalloonOverlay1.Initialize(MapView1, "", "balloon_overlay")
MapView1.AddOverlay(MarkersBalloonhOverlay1)
...
...
Dim XY As Marker
Dim XYListe As List 
XYListe.Initialize 

If GPS1.Latitude<>0 AND GPS1.Longitude<>0 Then
  XY.Initialize("Text", "Text", GPS1.Latitude, GPS1.Longitude, Icon)
  XY.MarkerHotspot=XY.HOTSPOT_PLACE_CENTER 
  XYLliste.Add(XY)
end If
   
MarkersBalloonOverlay1.RemoveMarkers
MarkersBallonOverlay1.AddMarkers(Eigenliste)
....

Thanks for help...
 

warwound

Expert
Licensed User
Longtime User
Look at the MarkersBalloonOverlay documentation and you'll see it has a property:

FocusedMarker As MyOverlayItemWrapper
Get or Set the Marker whose Balloon is displayed.
Returns Null if no Balloon is displayed.

When you update your Markers check if FocusedMarker is a Marker or Null.

If it's not Null then you want to re-open the balloon on this Marker once it's re-positioned.

B4X:
Dim FocusedMarker As Marker=MarkersBalloonOverlay1.FocusedMarker

MarkersBalloonOverlay1.RemoveMarkers
MarkersBallonOverlay1.AddMarkers(Eigenliste)

If FocussedMarker<>Null Then
   ' you need to iterate through your List Eigenliste and find which new instance of a Marker corresponds to the old instance FocussedMarker
   ' if your Markers have unique Title properties then you could do
   For Each Marker1 As Marker In Eigenliste
      If Marker1.Title=FocussedMarker.Title Then
         MarkersBalloonOverlay1.FocusedMarker=Marker1
         Exit
      End If
   Next
End If

If your Markers do not have unique Titles or Descriptions then look at the Marker UniqueId property, which can be set using the Initialize4 method.

Make sure all your Markers have a UniqueId and if the baloon is open when you update your markers then search for a new Marker with the same Unique Id as the FocussedMarker.

Martin.
 

schimanski

Well-Known Member
Licensed User
Longtime User
A short question about the thread above:

I have tried to close the window of the focusedMarker with focusedMarker=Null.

That doesn't runs. Is it not possible to loose the focus by code?

thanks for help....
 

warwound

Expert
Licensed User
Longtime User
Have you tried to call the MapView Invalidate method after setting the focusedmarker to Null?

B4X:
MarkersBalloonOverlay1.FocusedMarker=Null
MyMapView.Invalidate

Martin.
 
Top