- Home /
How to instantiate an object at GPS coordinate?
Hi folks,
I would like to instantiate an object at some given coordinate. For example, I have GPS coordinates of my house and I would like to place an object at that location, then i would like to know if I'm near the object (unity renders the object close to the camera) or far (renders the object away to the camera - or invisible).
How can i do that?
(I'm also using vuforia for AR Camera)
hi if you would like instantiate object on gps position you need :
public Transform GPSPos; public GameObject TheObject;
void Update(){
Instantiate(TheObject, GPSPos.position, GPSPos.rotation);
}
Answer by DiGiaCom-Tech · May 27, 2017 at 09:18 PM
Convert the GPS coordinates into X/Z values (you can set the Y value based on the get terrain height at X/Z). Basically 1° degree Latitude/Longitude at the equator is approximately 111 Kilometers (111,000 meters). The math to convert Degrees° Minutes' Seconds" values to decimal meters is rather straight forward. Take a look at these links...
https://www.google.com/?gws_rd=ssl#q=meters+per+degree+latitude&spf=1495919126475
The problem you'll encounter is that GPS coordinates are spherical, that is, the farther North/South you get away from the equator the smaller the distances for X are (as they converge to a single point at the poles). The question you have to ask yourself is how BIG is the area you are working with? If a small area, then you really don't have to factor this compression in. If you are doing something that covers the whole globe then you'll have to do the math (remembering to factor in the diameter of your world).
Once you have the X/Y/Z values calculated the instantiation call is rather simple. Please let me know if you need assistance with that (your initial post was a little vague on what you were really asking for help with).
Wondering if this has been made any easier with MARS and AR+GPS plugins? Attempting something similar myself
Answer by M1tiens · May 29, 2019 at 09:14 AM
I'm also struggling with this. I managed already to get x and z coordinates from a gps coordinate, but i think they are wrong because the don't regard the initial device rotation, or in other words, i think i'm getting the absolute value of the gps location, but if a place is like 10 meters away from my current place, i don't know if it's in the positive or in the negative side of the axis. @DiGiaCom-Tech can you help me with this?
Your answer
Follow this Question
Related Questions
Cloud recognition in Vuforia 0 Answers
animations not change when OnGUI button click in unity3d Vuforia? 1 Answer
How can i get gps signal on my andriod without data or wifi 0 Answers
how to store the texture 1 Answer
GPS doesn't work in AGPS mode 0 Answers