Android Question Location Update crashing the Application

AndroidMadhu

Active Member
Licensed User
Hello,
when I am running the below code the application is crashing.
What the code is performing like if the location is same or not changed then no Lat/Long will be send to mqtt. If any location changed happened then the code will throw the new lat/long to mqtt.

B4X:
If lastLocation.Latitude <> newloc.Latitude And lastLocation.Longitude <> newloc.Longitude And newloc.Latitude<>0 And newloc.Longitude<>0 Then

But If I omit the above line the application running fine as expected.
The full code is for your reference...
B4X:
Sub Update_Location(newloc As Location)
Dim strLoc As String

If lastLocation.Latitude <> newloc.Latitude And lastLocation.Longitude <> newloc.Longitude And newloc.Latitude<>0 And newloc.Longitude<>0 Then <==== Here i am facing the issue. Without this line application is rununning fine.
lastLocation=newloc
strLoc="lastLocation_" & lastLocation.Latitude & "/" & lastLocation.Longitude '& qrActivity.sessionId
Log(strLoc)
If newloc.IsInitialized Then
Dim CameraPosition1 As CameraPosition 'CameraPosition1.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom, 0, 0)
CameraPosition1.Initialize(newloc.Latitude,newloc.Longitude, 17)
gmap.moveCamera(CameraPosition1)
Log("Update Location")
ToastMessageShow("Update_Location",True)
Dim bc As ByteConverter

strLoc="newloc_" & newloc.Latitude & "/" & newloc.Longitude '& qrActivity.sessionId
Log(strLoc)
Log("driver_" & qrActivity.sessionId)
mqtt.Publish("driver_" & qrActivity.sessionId,bc.StringToBytes(strLoc ,"UTF8"))
Else
Log("No Update")

End If
End If
End Sub

Please advice
 

drgottjr

Expert
Licensed User
Longtime User
and in addition to sharing the log, you might want to reconsider that test regarding one set of coordinates being equal to another. even when you're standing still, the gps is throwing minutely varying readings. the test is probably never going to be false. also, latitude 0.0 and longitude 0.0 are perfectly legal readings. if you're testing for legality or an actual reading, 0 is not the way to go.
 
Upvote 0
Top