GPS coordinates (lat/long/altitude) to Unity 3D coordinates (x, y, z)

Hi,

I’m trying to put the Unity camera into the “real” 3D space by reading the GPS coordinates and converting them to Unity 3D coordinates, and then setting the camera position to those 3D coordinates. I’m also trying to put some objects into the “real” space around the user, so they show up when the user points his mobile device at those objects (I’m using the gyroscope to detect the rotation).

The problem I’m having is that I can’t seem to find a method to convert those GPS coordinates to Unity 3D coordinates so they match up (I know they can’t match up 100%, but in my case they don’t match even slightly). I’ve tried a few methods that were mentioned here, I even tried converting the method found here to C# (the function called llhxyz, along with its related functions that calculate the constants), but even that didn’t give me satisfying results. I am also aware that the ECEF XYZ coordinates are not equivalent to Unity’s XYZ, but even switching them around doesn’t help.

Can anyone push me in the right direction or tell me what I’m doing wrong?

Perhaps you need to increase your accuracy. I'm not sure if these issues still exists but its worth reading: [http://answers.unity3d.com/questions/759854/unity3d-location-services-not-updating-regularly.html][1] [1]: http://answers.unity3d.com/questions/759854/unity3d-location-services-not-updating-regularly.html

Hi, I'm having exactly the same problem. Did you find a solution for this ?

@schpinn l.O, Did you succeed to do what you want ? COuld you tell me how to do all of this ? I would like to do exactly the same thing and it is urgent thanks for all my mail :mmmklmail@gmail.com

By infinity, i think they mean a very high value

2 Answers

2

First of all there is no answer “how to convert lat/long to Unity coordinates”, because Unity coordinates can be anything. There is no official rule how you convert real world, to Unity coordinates. It all depends what you choose your Unity coordinates to be.

The most simple thing would be to treat lat/long/altitude as coordinates on a sphere (that’s what they are) and just render such sphere with user position in Unity. If that’s not what you’re after, then you have to modify to what Unity coordinates in your project mean.

Thanks for your answer. I chose that 1 Unity unit corresponds to 1 real word meter (it seemed to me that would be the easiest for conversion).

Well... when you say 1 Unity unit = 1 meter, you're kinda implying that your coordinate system is orthogonal. And lat-long is not - it's spherical. So you can not just assign lat-long-atlitude to xyz and expect it to work (well you can in local area, but don't start thinking about that). Read about how to convert spherical coordinate system to orthogonal. It should be something along those lines: // this gives you a point on a spehere const float kRadiusOfEarth = 6000; Vector3 pos = new Quaternion(lat, long, 0) * new Vector3(0, 0, kRadiusOfEarth + altitude);

Even if that's the case, setting the value of these fields to a value that's too high (such that the value is displayed as an exponent) also throws an error. Anyway, even if you set the values to 99999, you won't be able to notice a difference between than and setting it to 5000, because the underlying functionality remains the same.

@schpinn
l.O,
Did you succeed to do what you want ?
COuld you tell me how to do all of this ?
I would like to do exactly the same thing and it is urgent
thanks for all
my mail :mmmklmail@gmail.com