Android Question xSD_OpenMaps & jSD_OpenMaps

stevel05

Expert
Licensed User
Longtime User
Using this great library in a B4a and B4j (appropriate versions) cross platform B4xPages app. I am trying to obtain some information on the state of a map view when it is closed, so I can reset it when next opened. I have the sub in a customview that hosts an OpenMaps instance:

Code: Copy
Private Sub btnBack_Click
    wait for (OMaps.getZoom) Complete (Zoom As Int)
    Log("Zoom " & Zoom)
    Wait for (OMaps.XYToLatLng(OMaps.mBase.Width / 2, OMaps.mBase.Height / 2)) Complete (Center As LatLng)
    Log("Center " & Center)
    Wait For(OMaps.CameraPosition) Complete (Pos As CameraPosition)
    Log("CP " & Pos)
 
    Close
    CallSubDelayed2(mCallBack, mEventName & "_Closed", mIndex)
 
End Sub

In B4a getZoom and XYToLatLng both return values, not sure on the validity of XYToLatLng though, so thought I'd use CameraPosition, but in B4a I get the error:

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.openmaps$ResumableSub_CameraPosition.resume(openmaps.java:850)
    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.openmaps$ResumableSub_CameraPosition.resume(openmaps.java:850)
    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)

In B4j nothing is ever returned from any of the methods and the app just hangs.

I have tried different program flows including calling the methods in a CallSubDelayed before closing, just in case there were too many resumablesub calls.

Any advice / known issues before I create a test app (could take a while)?
 
Last edited:
Thanks StarDust, it looks like Android version CameraPosition is returning values very close to that I am setting when showing the map (more accuracy). Will have to finish the save / restore code to check properly, but looks like it will do what I need.
 
Upvote 0
As for the B4J version (jSD_OpenMaps), it is different from those for Android and iOS (xSD_OpenMaps). If they had the same syntax I would have put them on the same library thread.

Mobile versions require wait for to wait for results. The B4J version does not require wait for, using it you get no results.
You should use this code:
B4X: Copy
Log(GMap.getZoom)
Log(GMap.XYToLatLng(GMap.mBase.Width / 2, GMap.mBase.Height / 2))
Log(GMap.CameraPosition)
 
Upvote 0
Back
Top