So lets say I have a list of LatLng, maybe 100-500 items. Whenever the phone's GPS is changed, I iterate through the list to check the distance of the new location to every item in the list.
If the distance is <= X then execute some code, else, execute some other code.
Is this practice bad? The list is already going to be loaded with the LatLngs, so it won't change.
Example:
I never went to school for programming so I have no idea if this is bad or not, big O notation or whatever :\
In my mind, it's a good idea, but I dont want to slow down the user's phone if there are 500+ LatLngs in the list each time they move.
I could add a check and only run through the list if they move a certain amount, but depending on GPS accuracy, this might not work all the time.
Ex:
What do you guys think?
If the distance is <= X then execute some code, else, execute some other code.
Is this practice bad? The list is already going to be loaded with the LatLngs, so it won't change.
Example:
B4X:
Dim myLatLngs As List 'List holding anywhere from 50-500 LatLngs
'GPS location change event
Public Sub LocationChanged(Location1 As Location)
For i = 0 To myLatLngs.Size - 1
If MeasureDist(Location1, myLatLngs.Get(i)) <= 1600 Then
'Run code if distance is less than 1600 meters
End If
Next
End Sub
I never went to school for programming so I have no idea if this is bad or not, big O notation or whatever :\
In my mind, it's a good idea, but I dont want to slow down the user's phone if there are 500+ LatLngs in the list each time they move.
I could add a check and only run through the list if they move a certain amount, but depending on GPS accuracy, this might not work all the time.
Ex:
B4X:
Dim LastLocation As LatLng
If MeasureDist(Location1, LastLocation) >= 500 Then 'only loop through list if they have moved more than 500 meters
LastLocation = Location1
For i = 0 To myLatLngs.Size - 1
If MeasureDist(Location1, myLatLngs.Get(i)) <= 1600 Then
'Run code if distance is less than 1600 meters
End If
Next
Else
LastLocation = Location1
End If
What do you guys think?