How to get World position from Latitude and Longitude values?

Hi All, I am developing a Location-Based AR application. I want to get the world position from the Latitude and Longitude values in that application. I am attaching script references that I have tried, Please check:

I am getting the XYZ values from Latitude and Longitude like this : (6378137.0, 12.7, -12.7)

Can anyone please help me to get the Unity world position from Latitude and Longitude values?

Thanks in advance.

8011568–1031027–Location.cs (2.3 KB)

Unity doesn’t have a concept of longitude or latitude, it’s a virtual 3d space. There is no such thing as the ‘Unity world position’ from the longitude and latitude coordinate’s you’re supplying.

So what ‘world position’ are you asking to calculate? In-game Unity world, or the real world? Does you game have a sphere inside it, and you’re asking how to map longitude and latitude coordinates onto that sphere?

1 Like

I had a think about it and I think you have lat/long coordinates and just want to represent them in Unity on an arbitrary sphere, idk why I didn’t get that the first time.

Since Lat and Long are both just angles in degrees, this is easily done using Quaternion.Euler()

float _long = -47.62962705129123f;
float _lat = -136.7416840191186f;
float radius = 10;

Vector3 point = new Vector3(radius, 0, 0);
point = Quaternion.Euler(0, _lat, _long) * point;

point in this example now represents where those lat/long coordinates equate to in the scene assuming a radius of 10 and centered at world zero.

Here’s a video showing that exact method working.

Hi @ZBerm , Thank you so much for your response. I have to place the Gameobjects at some specific Geo Locations by using the Latitude and Longitude values. Can you please share some references for this implementation?

Easy, just use point as the position you want to spawn the GameObjects at.

As for references, hm I’m not sure what to give you. This Unity Answer is doing the same thing you are:

And of course the docs for Euler