F fraxinus Member Licensed User Longtime User Aug 6, 2011 #1 Could A.K.S show some examples of the Location.Distanceto and how accurate is it. I have Racing Pigeons and would like to develop an app to give accurate distances between two given Lat/Long coordinates. thanks Rob
Could A.K.S show some examples of the Location.Distanceto and how accurate is it. I have Racing Pigeons and would like to develop an app to give accurate distances between two given Lat/Long coordinates. thanks Rob
derez Expert Licensed User Longtime User Aug 6, 2011 #2 Here is an example: Code: Copy 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. Upvote 0
Here is an example: Code: Copy 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.
F fraxinus Member Licensed User Longtime User Aug 6, 2011 #3 Sorry David, but I was after examples of code to measure the distance of 2 fixed lat/long positions. i.e Distance between Lat1:51:37:42.66 N, Lon1: 3:55:44.09 W and Lat2: 51:23:51.55 N Lon2: 1:18:3.61 W I've used several examples of the Great Circle method (see one below)but the results are not accurate. Sub CalcDistance_click Dim Lat1 As Double, Long1 As Double, Lat2 As Double, Long2 As Double Dim EarthRadius, Angle, Distance As Double EarthRadius = 6378.167 'WGS - 84 Angle = ACos(SinD(Lat1) * SinD(Lat2) + CosD(Lat1) * CosD(Lat2) * CosD(Long2 - Long1)) Distance = EarthRadius * Angle Return Distance End Sub Upvote 0
Sorry David, but I was after examples of code to measure the distance of 2 fixed lat/long positions. i.e Distance between Lat1:51:37:42.66 N, Lon1: 3:55:44.09 W and Lat2: 51:23:51.55 N Lon2: 1:18:3.61 W I've used several examples of the Great Circle method (see one below)but the results are not accurate. Sub CalcDistance_click Dim Lat1 As Double, Long1 As Double, Lat2 As Double, Long2 As Double Dim EarthRadius, Angle, Distance As Double EarthRadius = 6378.167 'WGS - 84 Angle = ACos(SinD(Lat1) * SinD(Lat2) + CosD(Lat1) * CosD(Lat2) * CosD(Long2 - Long1)) Distance = EarthRadius * Angle Return Distance End Sub
Erel B4X founder Staff member Licensed User Longtime User Aug 7, 2011 #4 Here is an example: Code: Copy Dim loc1, loc2 As Location loc1.Initialize2("36.5", "30.123") loc2.Initialize2("40", "40") Log(loc1.DistanceTo(loc2)) Log(loc1.BearingTo(loc2)) This is a native method and the documentation doesn't mention its accuracy. Upvote 0
Here is an example: Code: Copy Dim loc1, loc2 As Location loc1.Initialize2("36.5", "30.123") loc2.Initialize2("40", "40") Log(loc1.DistanceTo(loc2)) Log(loc1.BearingTo(loc2)) This is a native method and the documentation doesn't mention its accuracy.
klaus Expert Licensed User Longtime User Aug 7, 2011 #5 Hi fraxinus. Erel's solution is what you are looking for. I tried your example from this thread Measurement of distance. The resut is 184.220... . DistanceTo is probably calculating with the Vincenty's formula Best regards. Upvote 0
Hi fraxinus. Erel's solution is what you are looking for. I tried your example from this thread Measurement of distance. The resut is 184.220... . DistanceTo is probably calculating with the Vincenty's formula Best regards.
F fraxinus Member Licensed User Longtime User Aug 7, 2011 #6 Thanks Erel and Klaus for your invaluable help. The code is very close too what I require at the moment. I've tried all of the various Great Circle formulae. Haversine, Spherical Law of Cosines,etc also using various Earth Radius from the mean radius of 6,371km to WGS - 84 Ellipsoid of:sign0098: 6378.167 kms . All have given basically the same resulting distances, but were also out by a few hundred meters in my coding. Could you tell me what Earth radius is used in the example Erel posted, and could it be altered? Many thanks all Rob Upvote 0
Thanks Erel and Klaus for your invaluable help. The code is very close too what I require at the moment. I've tried all of the various Great Circle formulae. Haversine, Spherical Law of Cosines,etc also using various Earth Radius from the mean radius of 6,371km to WGS - 84 Ellipsoid of:sign0098: 6378.167 kms . All have given basically the same resulting distances, but were also out by a few hundred meters in my coding. Could you tell me what Earth radius is used in the example Erel posted, and could it be altered? Many thanks all Rob
klaus Expert Licensed User Longtime User Aug 7, 2011 #7 The code Erel proposed is the calculation provided by the Android GPS location class. As I wrote in my prvious post, I suppose that it uses the Vincenty's formulas. Googling around for Vincenty's formulas I found a site with a distance calculator with these formulas and found the result that you were expecting. These equations are much more 'sophisticated' than the 'Grand circle' formulas I have tested like you with the same results as you, they all give the same result. I too, tried with different Earth radiuses, but that's not the difference we expect. Best regards. Upvote 0
The code Erel proposed is the calculation provided by the Android GPS location class. As I wrote in my prvious post, I suppose that it uses the Vincenty's formulas. Googling around for Vincenty's formulas I found a site with a distance calculator with these formulas and found the result that you were expecting. These equations are much more 'sophisticated' than the 'Grand circle' formulas I have tested like you with the same results as you, they all give the same result. I too, tried with different Earth radiuses, but that's not the difference we expect. Best regards.
F fraxinus Member Licensed User Longtime User Aug 7, 2011 #8 Hi Kaus Yes, I tried out Vincenty's formulae and it matches the Calculation provided by Android GPS location class. He uses GRS-80 Ellipsoid radius of 6378.137 m You have been extremely helpful. Thanks All Rob Upvote 0
Hi Kaus Yes, I tried out Vincenty's formulae and it matches the Calculation provided by Android GPS location class. He uses GRS-80 Ellipsoid radius of 6378.137 m You have been extremely helpful. Thanks All Rob
O ogransjo New Member Licensed User Longtime User Oct 5, 2011 #9 Is it possible to put this in a Service Module ? derez said: Here is an example: Code: Copy 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. Click to expand... I want to have this in a Service Module. Is it possible? I need a example :BangHead: Upvote 0
Is it possible to put this in a Service Module ? derez said: Here is an example: Code: Copy 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. Click to expand... I want to have this in a Service Module. Is it possible? I need a example :BangHead:
Erel B4X founder Staff member Licensed User Longtime User Oct 6, 2011 #10 You can put this exact code in a service. Just call StartService to make it start. Basic4android Search: Service tutorial Upvote 0
You can put this exact code in a service. Just call StartService to make it start. Basic4android Search: Service tutorial
netchicken Active Member Licensed User Longtime User Oct 31, 2011 #11 OK, I feel stupid, but I am just not getting this location.distanceto calculation. location.latitude and location.longitude are obvious, how do you get the location.to() calculation when you can only store lat and lon? Sure its seems to be current location - stored location, but as location is divided into 2 components how does it work? Also, what is speed measured in? Meters per second? Last edited: Oct 31, 2011 Upvote 0
OK, I feel stupid, but I am just not getting this location.distanceto calculation. location.latitude and location.longitude are obvious, how do you get the location.to() calculation when you can only store lat and lon? Sure its seems to be current location - stored location, but as location is divided into 2 components how does it work? Also, what is speed measured in? Meters per second?
Erel B4X founder Staff member Licensed User Longtime User Oct 31, 2011 #12 location.latitude and location.longitude are obvious, how do you get the location.to() calculation when you can only store lat and lon? Click to expand... Location.DistanceTo returns the distance in meters between two Location objects. The current one and the one passed as a parameter. Also, what is speed measured in? Meters per second? Click to expand... Basic4android Search: location.speed Upvote 0
location.latitude and location.longitude are obvious, how do you get the location.to() calculation when you can only store lat and lon? Click to expand... Location.DistanceTo returns the distance in meters between two Location objects. The current one and the one passed as a parameter. Also, what is speed measured in? Meters per second? Click to expand... Basic4android Search: location.speed
netchicken Active Member Licensed User Longtime User Oct 31, 2011 #13 Thank Erel. I really had a brain futz there. I got it working OK Upvote 0