I am making an AR app that obtains the user’s GPS position (latitude/longitude) and the GPS position of some points of interest (yes, I am using the GeoLocation plugin).
Then actors or static meshes are instantiated in those positions of interest.
I can calculate and display on the screen the distance that separates the user from these points of interest.
The problem is that the actors created at these points are at a distance that does not correspond to reality.
By transforming its gps position to Cartesian coordinates, in UE4 the separation distance is very short, so much so that it seems that these points of interest are overlapping, when in reality they are separated by more than 50 meters.
This is the function that is used to convert gps coordinates to cartesian.
# Converting lat/long to cartesian
import numpy as np
def get_cartesian(lat=None,lon=None):
lat, lon = np.deg2rad(lat), np.deg2rad(lon)
R = 6371 # radius of the earth
x = R * np.cos(lat) * np.cos(lon)
y = R * np.cos(lat) * np.sin(lon)
z = R *np.sin(lat)
return x,y,z
The distance between gps points is obtained using the Harvesine formula.
static double CalculateDistanceBetween(const Coord& c1, const Coord& c2)
{
return EARTH_RADIUS * acos(cos(ToRadians(90 - c1.Latitude)) * cos(ToRadians(90 - c2.Latitude)) + sin(ToRadians(90 - c1.Latitude)) * sin(ToRadians(90 - c2.Latitude)) * cos(ToRadians(c1.Longitude - c2.Longitude)));
}
If I multiply the Cartesian coordinates obtained by a factor of 100 (1uu = 1cm * 100 = 1m) the points of interest are more separated (although not as in reality, maybe) but the speed at which I access them is higher than reality.
What am I missing? (no matter the bad precision of the mobile devices, with the precision of >10m it is enough for me)
Greetings