#### Topic: distance & altitude

Hi

I want to measure the exact distance between to points.

Those two points are defined by a latitude, longitude, and altitude.

OnlineMapsUtils provide two functions : one that doesn't take the altitude into account, and one that does.

However when i try to compare the result of the two method, i get roughly the same result. See the example below :

https://gph.is/g/a9pOAOJ

`````` //GpsCoordinates is lat, lng, and altitude in meters
GpsCoordinates A = new GpsCoordinates(48.332300, -70.992836, 0);
GpsCoordinates B = new GpsCoordinates(48.332200, -70.992836, 0.2); //small difference in latitude, 200 meters difference in altitude

double dx, dy;
OnlineMapsUtils.DistanceBetweenPoints(A.Longitude, A.Latitude, B.Longitude, B.Latitude, out dx, out dy);

Debug.Log("distance between A and B (no altitude taken into account) : " + Math.Sqrt(dx * dx + dy * dy) * 1000 + " m");

OnlineMapsUtils.DistanceBetweenPoints(A.Longitude, A.Latitude,(float)A.Altitude, B.Longitude, B.Latitude,(float)B.Altitude, out dx, out dy);

Debug.Log("distance between A and B (altitude should matter in the result): " + Math.Sqrt(dx * dx + dy * dy) * 1000 + " m");

//representation of the two points on the map :

string label = "PointA";
OnlineMapsMarker3D marker = OnlineMapsMarker3DManager.instance.Create(A.Longitude, A.Latitude, prefab);
marker.prefab.name = label;
marker.altitudeType = OnlineMapsAltitudeType.relative;
marker.altitude = (float)A.Altitude*1000;

label = "PointB";
OnlineMapsMarker3D marker2 = OnlineMapsMarker3DManager.instance.Create(B.Longitude,B.Latitude, prefab);
marker2.prefab.name = label;
marker2.altitudeType = OnlineMapsAltitudeType.relative;
marker2.altitude = (float)B.Altitude*1000;``````

This is what i get : I was expecting the distance to be 200 meters and more. How can i get the exact distance between my two points ?

#### Re: distance & altitude

Hello.

This method is completely wrong.
Thank you for reporting this.
This method is marked as obsolete and incorrect.

The new version of the method (the next version will contain this):

``````public static double DistanceBetweenPoints(double x1, double y1, double a1, double x2, double y2, double a2)
{
double r = R + Math.Min(a1, a2);
double scfY = Math.Sin(y1 * Deg2Rad);
double sctY = Math.Sin(y2 * Deg2Rad);
double ccfY = Math.Cos(y1 * Deg2Rad);
double cctY = Math.Cos(y2 * Deg2Rad);
double cX = Math.Cos((x1 - x2) * Deg2Rad);
double sizeX1 = Math.Abs(r * Math.Acos(scfY * scfY + ccfY * ccfY * cX));
double sizeX2 = Math.Abs(r * Math.Acos(sctY * sctY + cctY * cctY * cX));
double dx = (sizeX1 + sizeX2) / 2.0;
double dy = r * Math.Acos(scfY * sctY + ccfY * cctY);
if (double.IsNaN(dx)) dx = 0;
if (double.IsNaN(dy)) dy = 0;
double d = Math.Sqrt(dx * dx + dy * dy);
double hd = Math.Abs(a1 - a2);
return Math.Sqrt(d * d + hd * hd);
}``````
Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!