B4A Class Open Street Map viewer - GPS

MbedAndroid

Well-Known Member
Licensed User
Longtime User
cvmap giving crashes. Got one of them during the exercises.
firebase output:
Fatal Exception: java.lang.RuntimeException
Object should first be initialized (B4XView).



anywheresoftware.b4a.AbsObjectWrapper.getObject (AbsObjectWrapper.java:67)


anywheresoftware.b4a.objects.B4XViewWrapper.getTag (B4XViewWrapper.java:600)


com.TrainingApp.cvmap._latlngtopoint (cvmap.java:1013)

com.TrainingApp.cvmap._update_gps (cvmap.java:1778)

com.TrainingApp.cvmap._gps_locationchanged (cvmap.java:970)

com.TrainingApp.main._updatechart (main.java:9304)

java.lang.reflect.Method.invoke (Method.java)


anywheresoftware.b4a.keywords.Common.CallSubNew2 (Common.java:1069)

com.TrainingApp.tracker._gps_locationchanged (tracker.java:205)

java.lang.reflect.Method.invoke (Method.java)


com.android.internal.os.ZygoteInit.main (ZygoteInit.java:947)


trying to solve it in this way:
B4X:
public Sub LatLngToPoint(aLatLng As TMapLatLng) As TMapPoint
    Try
    'https://www.netzwolf.info/osm/tilebrowser.html?marker.x=12&marker.y=189&tx=1&ty=0&tz=1&ts=256#tile
    Dim v As B4XView=PointToTile(0,0)
    If v.IsInitialized=False Then  'from here
        Dim pp As TMapPoint
        pp.Initialize
        pp.fX=0
        pp.fY=0
        Return pp
    End If 'to here
    Dim txy As TMapTileXY=v.tag
    Dim gpx As Double=(txy.fX+(-v.Left/coMapUtilities.cTileSize))/Power(2,fMap.fZoomLevel)
    Dim gpy As Double=(txy.fy+(-v.top/coMapUtilities.cTileSize))/Power(2,fMap.fZoomLevel)
    Dim tx As TMapTileNumberOffset=LngToTileX(aLatLng.fLng,fMap.fZoomLevel)
    Dim ty As TMapTileNumberOffset=LatToTileY(aLatLng.fLat,fMap.fZoomLevel)
    Dim ppx As Double=(tx.fTile+(tx.fOffset/coMapUtilities.cTileSize))/Power(2,fMap.fZoomLevel)
    Dim ppy As Double=(ty.fTile+(ty.fOffset/coMapUtilities.cTileSize))/Power(2,fMap.fZoomLevel)
    Dim p As TMapPoint=coMapUtilities.initPoint(fTilesCount*coMapUtilities.cTileSize*(ppx-gpx),fTilesCount*coMapUtilities.cTileSize*(ppy-gpy))
    Return p

End Sub
 
Last edited:

MbedAndroid

Well-Known Member
Licensed User
Longtime User
found another crash
Fatal Exception: java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:91)
at anywheresoftware.b4a.objects.B4XViewWrapper.getTag(B4XViewWrapper.java:600)
at com.TrainingApp.cvmap._latlngtopoint(cvmap.java:1013)
at com.TrainingApp.cvmap._update_gps(cvmap.java:1781)
at com.TrainingApp.cvmap._gps_locationchanged(cvmap.java:970)
at com.TrainingApp.main._updatechart(main.java:9488)
at java.lang.reflect.Method.invoke(Method.java)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)

hope this solves the bug in the same way as post #122
B4X:
public Sub LatLngToPoint(aLatLng As TMapLatLng) As TMapPoint
    'https://www.netzwolf.info/osm/tilebrowser.html?marker.x=12&marker.y=189&tx=1&ty=0&tz=1&ts=256#tile
    Dim v As B4XView=PointToTile(0,0)
    If v.IsInitialized Then '<----add
    Dim txy As TMapTileXY=v.tag
    Dim gpx As Double=(txy.fX+(-v.Left/coMapUtilities.cTileSize))/Power(2,fMap.fZoomLevel)
    Dim gpy As Double=(txy.fy+(-v.top/coMapUtilities.cTileSize))/Power(2,fMap.fZoomLevel)
    Dim tx As TMapTileNumberOffset=LngToTileX(aLatLng.fLng,fMap.fZoomLevel)
    Dim ty As TMapTileNumberOffset=LatToTileY(aLatLng.fLat,fMap.fZoomLevel)
    Dim ppx As Double=(tx.fTile+(tx.fOffset/coMapUtilities.cTileSize))/Power(2,fMap.fZoomLevel)
    Dim ppy As Double=(ty.fTile+(ty.fOffset/coMapUtilities.cTileSize))/Power(2,fMap.fZoomLevel)
    Dim p As TMapPoint=coMapUtilities.initPoint(fTilesCount*coMapUtilities.cTileSize*(ppx-gpx),fTilesCount*coMapUtilities.cTileSize*(ppy-gpy))
    Else 'add from here
Dim p As TMapPoint
        p.Initialize
        p.fX=0
        p.fY=0
    End If 'to here
    Return p

      
End Sub
 

fungms

Member
Hi, for today is your app with this lib working normally? I'm looking for resolve problem of

or is there other working solution than changing UserAgent? Maybe own server?
 

aminoacid

Active Member
Licensed User
Longtime User
Hi, for today is your app with this lib working normally? I'm looking for resolve problem of
View attachment 168095
or is there other working solution than changing UserAgent? Maybe own server?


Check this out... works great ...

 

fungms

Member
How come I didn't find by myself, I've checked many many many old libs and apps, even became to an google developer and wrote down my credit card to them ... going to test it. THX
 

aminoacid

Active Member
Licensed User
Longtime User
I know why I didn't find - its only B4J and @Star-Dust has no B4A version

Maybe someone's fired up own server like https://github.com/Overv/openstreetmap-tile-server ? Any clue or direction will be appreciated for not loosing time

When StarDust was developing his library, many of us made a few donations towards his efforts and he graciously gave the contributors a copy of the source code. Perhaps you can approach him and see if he would be willing to do the same for you so you can maybe revise it for Android?
 

mw71

Well-Known Member
Licensed User
Longtime User
Hi, for today is your app with this lib working normally? I'm looking for resolve problem of
View attachment 168095
or is there other working solution than changing UserAgent? Maybe own server?
Hello,



I encountered the same issue with a PHP/JS project. At the time, it occurred during testing due to too many requests being made in too short a time. Waiting 24 hours resolved the issue.

Having your own tile server would certainly help, too — although I don't know anything about that.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…