Android Question xSD_OpenMaps Android

stevel05

Expert
Licensed User
Longtime User
I'm trying to add a circle on the android variant using the code:
Code: Copy
Wait For (OMaps.AddCircle(LL,60dip,2dip,xui.Color_Magenta,xui.Color_Transparent,0)) Complete (TC As MapCircle)

The circle is added, but the call never returns with a Mapcircle object.

I'd be grateful for your input.

** Edit

In addition I managed to get the MapCircle object by clicking on it, then I found I couldn't move it.
 
Last edited:
I'm trying to add a circle on the android variant using the code:
Code: Copy
Wait For (OMaps.AddCircle(LL,60dip,2dip,xui.Color_Magenta,xui.Color_Transparent,0)) Complete (TC As MapCircle)

The circle is added, but the call never returns with a Mapcircle object.

I'd be grateful for your input.
Wait For can return only if the asynchronous method raises its matching completion event. If OMaps.AddCircle(...) draws the circle but never raises AddCircle_Complete, the call will wait indefinitely.

Check the Android implementation of AddCircle in xsd_openmaps. It should raise a completion event with the returned object, for example:
Code: Copy
Private Sub AddCircle(... ) As ResumableSub   
Dim tc As MapCircle    ' Create and add the circle...   
CallSubDelayed2(Me, "AddCircle_Complete", tc)
Return tc
End Sub
Then consume the event with the library’s actual event name:
Code: Copy
Wait For (OMaps.AddCircle(LL, 60dip, 2dip, _
    xui.Color_Magenta, xui.Color_Transparent, 0)) _
            Complete (TC As MapCircle)
If AddCircle is meant to be synchronous, remove Wait For and assign its return value directly instead. The method signature and implementation determine which form is correct.
 
Upvote 0
Thanks GMan but xsd_openmaps is a java or compiled library and I wouldn't look into them or B4xLibs without permission , otherwise I would have checked. I couldn't recompile it anyway.
 
Last edited:
Upvote 0
I'm trying to add a circle on the android variant using the code:
Code: Copy
Wait For (OMaps.AddCircle(LL,60dip,2dip,xui.Color_Magenta,xui.Color_Transparent,0)) Complete (TC As MapCircle)

The circle is added, but the call never returns with a Mapcircle object.

I'd be grateful for your input.

** Edit

In addition I managed to get the MapCircle object by clicking on it, then I found I couldn't move it.

Not all functions need Wait For. See the examples I have attached to the library.

Code: Copy
Dim Circle As MapCircle = OMap.AddCircle(ll,60dip,2dip,xui.Color_Magenta,xui.Color_Transparent,0)
Log(Circle.ID)
 
Upvote 0
So that one is not a Wait For. OK, Thanks. Got the object reference now.

Create using
Code: Copy
TrackCursor = OMaps.AddCircle(LL,60dip,8dip,xui.Color_Magenta,xui.Color_Magenta,1)

Trying to move it with:
Code: Copy
Dim LL As LatLng = mPointsList.Get(Index)
Log("UTC " & Index)
OMaps.UpdateCircleCenter(TrackCursor.ID,LL.Latitude,LL.Longitude)

Is that the right syntax?

My index tracking is working
Same code is working with B4j.
 
Upvote 0
So that one is not a Wait For. OK, Thanks. Got the object reference now.

Create using
Code: Copy
TrackCursor = OMaps.AddCircle(LL,60dip,8dip,xui.Color_Magenta,xui.Color_Magenta,1)

Trying to move it with:
Code: Copy
Dim LL As LatLng = mPointsList.Get(Index)
Log("UTC " & Index)
OMaps.UpdateCircleCenter(TrackCursor.ID,LL.Latitude,LL.Longitude)

Is that the right syntax?

My index tracking is working
Same code is working with B4j.
Yes, is correct
 
Upvote 0
OK, thanks. I have written a little Cross Platform test app this is the entirety of the code:

Code: Copy
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private OMaps As OpenMaps
    Private OMapsExt As OpenMapsExt
    Private CurrentPoint As MapCircle
    #if B4J
    Dim fx As JFX
    #End If
    
    Dim StartPointLL As LatLng
    Dim Point1LL As LatLng
    Dim Pos As Int = 0
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    OMapsExt.Initialize(OMaps)
    StartPointLL.Initialize(51.5080990163571, -0.07612096300477675)
    Point1LL.Initialize(51.50835595060191, -0.09860095046380832)
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click

    If Pos = 0 Then
        OMaps.UpdateCircleCenter(CurrentPoint.ID,Point1LL.Latitude,Point1LL.Longitude)
    Else
        OMaps.UpdateCircleCenter(CurrentPoint.ID,StartPointLL.Latitude,StartPointLL.Longitude)
    End If
    
    Log(Pos)
    
    If Pos = 0 Then
        Pos = 1
    Else
        Pos = 0
    End If
End Sub

Private Sub OMaps_Ready
    Log("OMaps Ready")
    
    #if B4A
    OMaps.MoveCamera2(StartPointLL)
    Sleep(1000)
    OMaps.SetZoom(15)
    CurrentPoint = OMaps.Addcircle(StartPointLL,15,5,xui.Color_Magenta,xui.Color_Magenta,1)
    #else
    OMaps.MoveCamera2(StartPointLL)
    OMaps.Zoom = 13
    CurrentPoint = OMaps.Addcircle(StartPointLL,15,5,fx.Colors.Magenta,fx.Colors.Magenta,1)
    #End If
    
End Sub

and attached the B4xPages project. On B4j, it works as intended, on B4a it doesn't can you shed any light on this please.
 

Attachments

Upvote 0
Sorry Star-dust, Markers appear to have the same problem:

Code: Copy
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

#Macro: Title, Export B4XPages, ide://run?File=%B4X%\Zipper.jar&Args=%PROJECT_NAME%.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private OMaps As OpenMaps
    Private OMapsExt As OpenMapsExt
'    Private CurrentPoint As MapCircle
    Private CurrentPointM As Marker
    #if B4J
    Dim fx As JFX
    #End If
 
    Dim StartPointLL As LatLng
    Dim Point1LL As LatLng
    Dim Pos As Int = 0
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    OMapsExt.Initialize(OMaps)
    StartPointLL.Initialize(51.5080990163571, -0.07612096300477675)
    Point1LL.Initialize(51.50835595060191, -0.09860095046380832)
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click

    If Pos = 0 Then
'        OMaps.UpdateCircleCenter(CurrentPoint.ID,Point1LL.Latitude,Point1LL.Longitude)
        OMaps.UpdateMarkerPosition(CurrentPointM.ID,Point1LL.Latitude,Point1LL.Longitude)
    Else
        OMaps.UpdateMarkerPosition(CurrentPointM.ID,StartPointLL.Latitude,StartPointLL.Longitude)
'        OMaps.UpdateCircleCenter(CurrentPoint.ID,StartPointLL.Latitude,StartPointLL.Longitude)
    End If
 
    Log(Pos)
 
    If Pos = 0 Then
        Pos = 1
    Else
        Pos = 0
    End If
End Sub

Private Sub OMaps_Ready
    Log("OMaps Ready")
 
    #if B4A
    OMaps.MoveCamera2(StartPointLL)
    Sleep(1000)
    OMaps.SetZoom(15)
'    CurrentPoint = OMaps.Addcircle(StartPointLL,15,5,xui.Color_Magenta,xui.Color_Magenta,1)
    CurrentPointM = OMaps.AddMarker(StartPointLL.Latitude,StartPointLL.Longitude,"Test")
    #else
    OMaps.MoveCamera2(StartPointLL)
    OMaps.Zoom = 13
'    CurrentPoint = OMaps.Addcircle(StartPointLL,15,5,fx.Colors.Magenta,fx.Colors.Magenta,1)
    CurrentPointM = OMaps.AddMarker(StartPointLL.Latitude,StartPointLL.Longitude,"Test")
    #End If
'    Log(CurrentPoint)
    Log(CurrentPointM)
 
End Sub

works in B4j, but not B4a.

Also I noticed that when the Circle or Marker is moved (only Tested in B4j), the LatLng values are not changed. Don't know if that's the underlying library or your wrapper not updating the values.
 
Last edited:
Upvote 0
Fixed marker bug (rel. 1.6). To read the position in B4a and B4I the code is this:

Code: Copy
wait for (Circle.GetCenter) COMPLETE (Position As LatLng)

At the moment I don't think there is an error in reading the positions after moving a circle or a marker in b4j
 
Upvote 0
I am trying to write a thorough test for the read positions but in B4a
Code: Copy
Wait For(CurrentCircle.GetCenter) Complete (CircleLL As LatLng)

Is causing a crash:
Code: Copy
java.lang.RuntimeException: JSON Object expected.
    at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:67)
    at anywheresoftware.b4a.objects.collections.JSONParser$JSONConverter.ToMap(JSONParser.java:289)
    at it.tecnomedia.omap.mapcircle$ResumableSub_GetCenter.resume(mapcircle.java:146)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:281)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:223)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:209)
    at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1867)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6816)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
java.lang.RuntimeException: JSON Object expected.
    at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:67)
    at anywheresoftware.b4a.objects.collections.JSONParser$JSONConverter.ToMap(JSONParser.java:289)
    at it.tecnomedia.omap.mapcircle$ResumableSub_GetCenter.resume(mapcircle.java:146)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:281)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:223)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:209)
    at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1867)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6816)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

If you can fix this, I will continue my testing.
 
Upvote 0
Yes Peter, it's called in the OMaps_Ready sub. And there is a sleep(1000) in there too as it doesn't like the zoom being set too quickly (Just for my test app).
 
Upvote 0
Back
Top