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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…