Hi All, I am developing a Location Based AR demo application using the LightShip SDK. I have to convert the Latitude and Longitude values into the XYZ coordinates of Unity. I am attaching the code reference that I have tried, Please check:

var rad = Math.PI / 180;
var lat = TargetLatitude * rad - currentLatitude * rad;
var lon = TargetLongitude * rad - currentLongitude * rad;
var a = 6378.137* 1000;
var e2 = 0.00669437999014;
var N = a / Math.Sqrt(1 - e2 * Math.Pow(Math.Sin(lat), 2));
var x = N * Math.Cos(lat) * Math.Cos(lon);
var y = N * Math.Cos(lat) * Math.Sin(lon);
var z = (1 - e2) * N * Math.Sin(lat);
Vector3 XYZ = new Vector3((float)x,(float)y,(float)z);

I am getting the XYZ coordinates like this (6378137.0, -11.0, 5.8) based on the code reference that I have shared.

Can anyone please help me how I can get the XYZ coordinates of Unity based on the Latitude and Longitude?

Hi Akhil, youâ€™ll need to implement functions to go to/from GPS coordinates (lat, lon) and the cartesian (x, y, z) coordinate system of the tracking system. This can be done by using GPS/compass while the AR Session is running, but the implementation needs to be done on your side. Thanks.

Hi Akhil, take a look at Scripting API: Compass reference, and Scripting API: LocationService.Start documentation to assist with your project. I hope this helps. Thanks.

Hi @Moranda_Nalls1, Thank you so much for your references. I was able to get the x, y, z values based on the LocationService.Start documentation this reference. I want to make the Gameobject direction to be the same as the specific GeoLocation Direction. I have tried the Compass reference but it is not giving the result that I am expecting.

Cab you please help me to make the Gameobject direction to be same as the specific GeroLocation direction?

Hello Akhil, you mentioned Compass didnâ€™t work. Did you happen to try Compass.trueHeading? If not, this will solve your issue. If yes, double check your code and please provide what happens when itâ€™s implemented.

public static class ExtraMath
{
public struct LocationToMeters
{
public static double Lon(double lon)
{
var x = lon * 2 * Math.PI * 6378137 / 2 / 180;
return x;
}
public static double Lat(double lat)
{
var y = Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
y = y * 2 * Math.PI * 6378137 / 2 / 180;
return y;
}
}
}

As far as I know Altitude is already in Meters.
Latitude and Longtitude needs to be â€śdestretchedâ€ť from a spherical mapping to get a 2D coordinate system that alligns with unitys.
You can plug in the lat and long from whatever source you want, I used this in combination with Mapbox because the whole compass service setup is done already.
And 1 Meter is exactly 1 Unity Unit if youre wondering