How to import GPS location coordinates from Android device?

Hello, I tried to get latitude and longitude coordinates from 'Google Nexus One' and I failed.

I used the LocationInfo struct, but I think there is something missing. I wrote an Update function attached to 'GUI Text' like this:

void Update()
{
    float lat, lon;

    LocationInfo li = new LocationInfo();

    lat = li.latitude;
    lon = li.longitude;

    guiText.text="LAT= "+ lat +"
LON= " + lon;
}

Always returns 0.

Any idea? Thanks in advance,

Joel

The answer to this is actually in the last place you’d expect. You have to first initialize the iPhoneSettings.StartLocationServiceUpdates() (Yes, I know you’re on android. You have to use iPhoneSettings anyway) and then when the services is up and running update your loc variable with loc = iPhoneInput.lastLocation;

Read more about it here: http://unity3d.com/support/documentation/ScriptReference/iPhoneSettings.StartLocationServiceUpdates.html

You are just creating an new LocationInfo object, which will always return 0. You should call a function to retrieve the values from your device.

I do not know which function you should call to retrieve them.

Hello everyone, this is surely easy to arrange as a problem, which aims to use using methods use “location” for Unity 3D?

Thank you

you have to add this :

void Start()

{
    Input.location.Start();
}

void update()

{

StartCoroutine(UpdateLocation()) ;
}

IEnumerator UpdateLocation()
{
Input.location.Start();

    // Wait until service initializes
    int maxWait = 20;
    while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
    {
        yield return new WaitForSeconds(1);
        maxWait--;
    }

    // Service didn't initialize in 20 seconds
    if (maxWait < 1)
    {
        Text singleText = mytext1.GetComponentInChildren<Text>();
        singleText.text = "Timed out";

    }
    // Connection has failed
    if (Input.location.status == LocationServiceStatus.Failed)
    {
        Text singleText = mytext1.GetComponentInChildren<Text>();
        singleText.text = "Unable to determine device location";

    }
    else
    {
        float lat = Input.location.lastData.latitude;
        float lon = Input.location.lastData.longitude;

}}