Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by schpinn · Jul 21, 2015 at 03:37 PM · c#coordinateslocationgps

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?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Jul 22, 2015 at 01:19 PM 0
Share

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

avatar image AYADIMehdi · Oct 02, 2015 at 09:21 AM 0
Share

Hi,

I'm having exactly the same problem.

Did you find a solution for this ?

avatar image mklmrt · Apr 10, 2018 at 04:29 PM 0
Share

@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

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Paulius-Liekis · Jul 22, 2015 at 12:11 PM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image schpinn · Jul 22, 2015 at 12:47 PM 0
Share

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).

avatar image Paulius-Liekis · Jul 22, 2015 at 06:39 PM 0
Share

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); 
avatar image schpinn · Jul 22, 2015 at 06:59 PM 0
Share

Again, thanks for answering.

I didn't try to just assign lat/long/alt to XYZ - as I said in my original question, I tried various methods of converting lat/long/alt to XYZ (most of them from this here forum), I even converted this JS function to C# (llhxyz):

http://www.oc.nps.edu/oc2902w/coord/geodesy.js

That function doesn't even use a sphere, but a WGS84 ellipsoid (the same one the GPS uses), and I still didn't get acceptable results.

Here's what I did - I converted the GPS coordinates of the mobile phone, put the camera at those XYZ coordinates (all while continually pinging the GPS and moving the camera to the new coordinates), used the gyroscope to deter$$anonymous$$e how the phone is rotated (and rotated the camera in the same way), put an object at a known coordinate around me (I tried both with a coordinate from Google $$anonymous$$aps, and with one I obtained manually from my phone's GPS), pointed my phone at where the object should be and it was way off.

I'm thinking I'm probably missing some vital piece of information, or I'm not understanding the problem I'm having correctly. How would you approach the issue I'm trying to solve?

EDIT: I'm not at my work computer right now so I don't have the Unity project, but do you think the formulas you gave would give acceptable results? Also, is everything correct with my approach?

avatar image Paulius-Liekis · Jul 22, 2015 at 07:19 PM 0
Share

EDIT: I'm not at my work computer right now so I don't have the Unity project, but do you think the formulas you gave would give acceptable results?

No, I wouldn't take that code for granted :)

I'm thinking I'm probably missing some vital piece of information, or I'm not understanding the problem I'm having correctly. How would you approach the issue I'm trying to solve?

One step at a time. Seriously.

  1. $$anonymous$$y guess is that your positioning code (i.e. transform of lat long) is correct, as long as translated the code correctly. You can test it by simply supplying some known points on the globe and measuring distance - you can compare that against what google maps give you based on same coordinates.

  2. $$anonymous$$ake sure that your positioning system provides you values on correct axes, i.e. some coordinate systems have Y up (like Unity), but some have Z up. Some use right handed coordinate system, some left handed. The fix: just swap two coordinates and change one sign if necessary.

  3. $$anonymous$$ake sure you know how to use gyro values. They give you orientation of gyro in screen space of device, and you have to transform it into device orientation "on a plane of the world". I get annoyed every time I have to solve this problem, because you face same problems as in 2nd step. As I said input is device orientation specific, so I would advice to lock device orientation of LandscapeLeft only (or one of those).

  4. Transform "device orientation on a plane of the world" into "device orientation on a sphere".

If you do all 4 correctly, then it should work. I have done it in the past, getting all those details right was hard :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to enable location dialog? 0 Answers

How can I get a city name given a latitude & longitude 1 Answer

Using external GPS device unity application -1 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges