Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GPS location on Android

Discussion in 'Android' started by stefann, Mar 23, 2011.

  1. stefann

    stefann

    Joined:
    Jan 4, 2011
    Posts:
    17
    Hi, I'm trying to read the location of my device in Unity. Maybe I'm doing something worng but I couldn't find any example how to do it the right way.

    Code (csharp):
    1. var textObject : GameObject;
    2. var loc = new LocationInfo();
    3. function Update () {
    4. textObject.guiText.text = "Latitude: " + loc.latitude ;
    5. }
    In this case I'm just trying to print the latitude to a GUIText object but it always gives me zero.
    I would really appreciate any help!
     
  2. Myx

    Myx

    Joined:
    Nov 29, 2010
    Posts:
    196
    Hello there!

    You're actually just creating a data-structure which can hold the info, you never assign it. You can fetch the location with this piece of code:

    Code (csharp):
    1.  
    2. loc  = iPhoneInput.lastLocation;
    3.  
    And yes I know you're on an android, you use iPhoneInput for both iPhones and Androids.