Sub GPS_LocationChanged (Location1 As Location)
If location1.AccuracyValid Then gps_red_timer.Enabled = False Else gps_red_timer.Enabled = True
point.Lat = Location1.Latitude
point.lon = Location1.Longitude
speed = location1.Speed * gps_speed_to_kmh ' =3.6
If speed > 1 Then track = location1.Bearing
If flag.tgt = 1 Then
bearing = location1.BearingTo(tgt_location)
range = location1.DistanceTo(tgt_location)
End If
Dim loc1, loc2 As Location
loc1.Initialize2("36.5", "30.123")
loc2.Initialize2("40", "40")
Log(loc1.DistanceTo(loc2))
Log(loc1.BearingTo(loc2))
Here is an example:
B4X:Sub GPS_LocationChanged (Location1 As Location) If location1.AccuracyValid Then gps_red_timer.Enabled = False Else gps_red_timer.Enabled = True point.Lat = Location1.Latitude point.lon = Location1.Longitude speed = location1.Speed * gps_speed_to_kmh ' =3.6 If speed > 1 Then track = location1.Bearing If flag.tgt = 1 Then bearing = location1.BearingTo(tgt_location) range = location1.DistanceTo(tgt_location) End If
The question of accuracy is almost not related to the calculation, but to the accuracy of the GPS positioning at the time of run. It depends on the number of satellites and the relative geometry between them. If the GPS on both pigeons are with good accuracy you'll get an RMS error of 20-50 meter.
Location.DistanceTo returns the distance in meters between two Location objects. The current one and the one passed as a parameter.location.latitude and location.longitude are obvious, how do you get the location.to() calculation when you can only store lat and lon?
Basic4android Search: location.speedAlso, what is speed measured in? Meters per second?