I'm trying to have Holograms be placed based on GPS location, and I've managed to reliably bring in a stream of GPS data into my application. The problem I keep running into is that the formula I'm using to convert from latitude, longitude, and altitude to Cartesian for Unity seems to be incorrect. I'm pretty terrible at GIS, so I was wondering if anyone had some ideas on what to use. There's got to be some universal formula everyone uses, right?!?
Here's the code I'm using:
`Vector3 WGS84ToCartesian(float lat, float lon, float h)
float earthRadius = 6378137.0f;
float cosLat = Mathf.Cos(lat * Mathf.PI / 180.0f); float sinLat = Mathf.Sin(lat * Mathf.PI / 180.0f); float cosLon = Mathf.Cos(lon * Mathf.PI / 180.0f); float sinLon = Mathf.Sin(lon * Mathf.PI / 180.0f); float f = 1.0f / 298.257224f; float C = 1.0f / Mathf.Sqrt(cosLat * cosLat + (1 - f) * (1 - f) * sinLat * sinLat); float S = (1.0f - f) * (1.0f - f) * C; float x = (earthRadius * C + h) * cosLat * cosLon; float y = (earthRadius * C + h) * cosLat * sinLon; float z = (earthRadius * S + h) * sinLat; return new Vector3(x, y, z); }`