Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

device location coordinates

anyone know about device location? i know how to get the device coordinates but how i do i know the coordiantes 2 meter form the device? how does it work?






Message #augmented-reality

Best Answers

  • MouledouxMouledoux Member
    Accepted Answer

    I don't know how to save it's location and reload it later. That's probably something you should check the documentation for.

    2m in front of the device is:

    Camera.main.transoform.position + Vector3.forward * 2f; // it maybe Camera.main.transform.forward
    


    The asset pack should have someway to tell you where that is in 'world' space. But if it doesn't, this is the LONG way.

    Length in meters of 1° of latitude = always 111.32 km

    Length in meters of 1° of longitude = 40075 km * cos( latitude ) / 360


    So to add 1m in latitude:

    111.32 km = 111320m

    1° / 111320 = 0.00000898311 <- this is how much you would +/- LATITUDE to move it 1m


    Long is based on Lat, but for this EXAMPLE let's say the latitude is the Tropic of Cancer, 23.5

    40075 km * cos( 23.5) / 360 = 102.0866km = 102087m (we rounded up that 0.6m)

    1° / 102087 = 0.00000979556 <- this is how much you would +/- LONGITUDE to move 1m at the defined lat.



    Knowing these numbers (which I actually think are too small for float values), we can manually set a Long/ l Lat. I'm also assuming that +X in this pack is the same as walking directly East, and +Z is walking North, but that may not be the case.

    We got 2m forward above in Unity space, but for world space, you need to get the camera pos ideally the asset pack has a way, otherwise, look here -> https://docs.unity3d.com/ScriptReference/LocationService.Start.html

    Then it's just:

    Vector3 camForward = Camera.main.transform.forward.normalize;
    Vector3 myGlobalPos = new Vector3(longitudeVal, altid, latitudeVal); // this should be your current pos
    Vector3 GPSoffset = camForward.Scale(myGlobalPos) * 2f; // you can change this 2 to any distancet you want
    

    GPSoffset is the final position in Lat/ Long units.

    (x, y, z) = (Longitude, Altitude, Latitude)

  • MouledouxMouledoux Member
    Accepted Answer

    GPS, isn't accurate enough get EXACT locations (as we learned above). If you just put it at the camera position, it's likely it will appear some meters away when you reload back in. Even in the video you can see the objects they've placed move around as the camera moves and updates its GPS position.

Answers

  • What do you mean by "how i do i know the coordiantes 2 meter form the device?"

    are you asking (for AR purposes) how to you know where to put something so it's 2m away from the user?

  • gbo999gbo999 Member

    yes this is my question.

  • Camera.main.transform.position + 'some vector 3'

    Just normalize the vector3, then multiply by 2. That will be 2m from the camera (the user) in whatever direction you give it.

  • gbo999gbo999 Member
    edited June 2020

    i am working with an asset from asset store that can give you the option to put ar objects dependent on coordinates. so i want to keep the ar prefab to stay at that location 2m from where the device was. so i want to save this location for future use

  • How are you tracking the cameras position in space?

    Are you using its actual GPS coordinates, does this asset pack have camera controls, is this asset pack Unity's AR core/ kit?

    If it is AR core / kit, same thing. If it's some 3rd part pack, I'd have to see it. For GPS coordinates, use something else, as the accuracy is only good up to like 3 or 4m without an external GPS, and converting to unity coordinates (while possible) doesn't look good.

  • gbo999gbo999 Member

    do you know another solution to put ar objects according to it's exact location?

  • Exact location relative to what? The camera, the room you're in, the world?

    Again, I'd have to know what asset pack you're using, but if your using GPS, then no. If it's AR core/ kit, yes. Anything else, I do not know.

  • Yea that one looks like you could get it pretty close. How to you normally go about placing an object in the world? Just do that + 2m.


    The original examples I gave should work here just fine.

  • gbo999gbo999 Member

    i use plane detection and when i touch the plane with my phone a prefab on the plane is created. so i want it to stay there after loading the application second time. so i want to save the coordinates but i don't know how longitude/altitude/latitude works for which one of them i give +2?

  • You don't need to add anything to anything if you want it to stay there.

    If you want it to be 2m away from there, which direction? Underground? altitude -2.

  • gbo999gbo999 Member

    so how do i keep it there when loading second time?

    not underground same level but just 2 meter infront of the device.

Sign In or Register to comment.