gps crash android

hi…first…sorry for my english…im trying to test gps on android, i can see long and lat, but just few seconds, then my app crash and close…can be a problem with my device?im using bq aquarius m5…or maybe is a code problem.?..im using this code…thanks for help…

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class gpsmio : MonoBehaviour
{
    public  Text lonText;
    public  Text latitudText;
    LocationInfo currentGPSPosition;



    IEnumerator Start()
    {
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
            yield break;
       
        // Start service before querying location
        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)
        {
            print("Timed out");
            yield break;
        }
       
        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            print("Unable to determine device location");
            yield break;
        }
        else
        {
            // Access granted and location value could be retrieved
            print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
           
            //lonText.text = "long:" + Input.location.lastData.longitude.ToString()  ;
           
            //latitudText.text ="lat:" + Input.location.lastData.latitude.ToString();

        }
       
        // Stop service if there is no need to query location updates continuously
        Input.location.Stop();
    }

   


}

i am also dealing with this same problem… i have tried 2 different scripts. one same as above and one a lot different. i found the issue is on input.location.start(). I’ve tried opening and closing the script on a button but it still crashes. i see my longitude and latitude coordinates for about 2 seconds till the app crashes. if i remove this line of code (input.location.Start()) my app does not crash. however it needs to be there to get the function to work.
any help would be much appreciated.

Hi, I’m also having a similar issue where the app crashes when location services is started on Android, but works fine on iOS. It use to work fine until I upgraded from Unity 5.4.2 to 5.4.3. What version of Unity are you using?

same issue here, with 5.5.0p2

Yeah, I’m seeing the same thing, just upgraded from 5.4 to 5.5.

I seem to have gotten around it by Stopping the Location services right after it runs, then querying the data.

// Start service before querying location
        if(Input.location.status != LocationServiceStatus.Running)
            Input.location.Start(500f,500f);

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

        // Stop service and then query
        Input.location.Stop();

Thanks, this got me on the right track just in time and is a very good start.
However this still crashes if another Application is running in the Background using location services. It seems that for some reason Unity does not detect that the service is already running, tries to start it again and crashes.
I tried to explicitly stop the service but this won’t help either.

Any update this problem ? :frowning:
i have same problem in unity 5.5.0p3 , crash on Android device

Any update on this guys? I’m having the same issue with 5.5.0f3

I had to switched back to 5.4.2 to fix the crash issue…

Hi and it works Or the issue persist?

@sanatos0021 It works fine with 5.4.2