# Convert GPS coordinates into Unity world space?

I am developing an AR application where a number of historical buildings are spawned around the player depending on his position when a target / QR Code is recognized.

I know the Lat/Lon of these buildings and I have the Lat/Lon of the player. I have already implemented the Harvesine algorithm and can calculate the relative bearing of the buildings:

public static double Harvesine(double lat1, double lon1, double lat2, double lon2)
{
double R = 6371000; // metres
double omega1 = ((lat1 / 180) * Mathf.PI);
double omega2 = ((lat2 / 180) * Mathf.PI);
double variacionomega1 = (((lat2 - lat1) / 180) * Mathf.PI);
double variacionomega2 = (((lon2 - lon1) / 180) * Mathf.PI);
double a = Math.Sin(variacionomega1 / 2) * Math.Sin(variacionomega1 / 2) +
Math.Cos(omega1) * Math.Cos(omega2) *
Math.Sin(variacionomega2 / 2) * Math.Sin(variacionomega2 / 2);
double c = 2 * Math.Asin(Math.Sqrt(a));

double d = R * c;

return d;
}

public static double Bearing(double lat1, double lon1, double lat2, double lon2)
{
double y = Math.Cos(lat1 * Math.PI / 180) * Math.Sin(lat2 * Math.PI / 180) - Math.Sin(lat1 * Math.PI / 180) * Math.Cos(lat2 * Math.PI / 180) * Math.Cos((lon2 - lon1) * Math.PI / 180);

radians = Math.Atan2(x, y) * 180 / Math.PI;

}


From here, how can I spawn the building relative to the player position? I have the distance (Harvesine) and the angle (Bearing), how can I get the Vector3 location?

• I made a library for this purpose, documentation is scarce and it's been over a year since I wrote it, but check it out: github.com/starikcetin/Eflatun.GeoUnity Sep 10, 2020 at 1:16
• I'll definitely check it out, thanks! Sep 10, 2020 at 1:29

public static Vector3 FromPolar(float angleRadians, float radius) {