Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

gps crash android

Discussion in 'Editor & General Support' started by arkano, Aug 2, 2016.

  1. arkano

    arkano

    Joined:
    Oct 4, 2012
    Posts:
    5
    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...
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class gpsmio : MonoBehaviour
    6. {
    7.     public  Text lonText;
    8.     public  Text latitudText;
    9.     LocationInfo currentGPSPosition;
    10.  
    11.  
    12.  
    13.     IEnumerator Start()
    14.     {
    15.         // First, check if user has location service enabled
    16.         if (!Input.location.isEnabledByUser)
    17.             yield break;
    18.        
    19.         // Start service before querying location
    20.         Input.location.Start();
    21.        
    22.         // Wait until service initializes
    23.         int maxWait = 20;
    24.         while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
    25.         {
    26.             yield return new WaitForSeconds(1);
    27.             maxWait--;
    28.         }
    29.        
    30.         // Service didn't initialize in 20 seconds
    31.         if (maxWait < 1)
    32.         {
    33.             print("Timed out");
    34.             yield break;
    35.         }
    36.        
    37.         // Connection has failed
    38.         if (Input.location.status == LocationServiceStatus.Failed)
    39.         {
    40.             print("Unable to determine device location");
    41.             yield break;
    42.         }
    43.         else
    44.         {
    45.             // Access granted and location value could be retrieved
    46.             print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
    47.            
    48.             //lonText.text = "long:" + Input.location.lastData.longitude.ToString()  ;
    49.            
    50.             //latitudText.text ="lat:" + Input.location.lastData.latitude.ToString();
    51.  
    52.         }
    53.        
    54.         // Stop service if there is no need to query location updates continuously
    55.         Input.location.Stop();
    56.     }
    57.  
    58.    
    59.  
    60.  
    61. }
     
  2. spkmark

    spkmark

    Joined:
    Dec 8, 2016
    Posts:
    6
    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.
     
  3. MstarAdmin

    MstarAdmin

    Joined:
    Nov 14, 2014
    Posts:
    1
    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?
     
  4. jice_nolaroads

    jice_nolaroads

    Joined:
    Oct 2, 2016
    Posts:
    21
    same issue here, with 5.5.0p2
     
  5. Dougomite

    Dougomite

    Joined:
    Jul 15, 2011
    Posts:
    58
    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.

    Code (CSharp):
    1. // Start service before querying location
    2.         if(Input.location.status != LocationServiceStatus.Running)
    3.             Input.location.Start(500f,500f);
    4.  
    5.         // Wait until service initializes
    6.         int maxWait = 20;
    7.         while (!(Input.location.status != LocationServiceStatus.Running) && maxWait > 0)
    8.         {
    9.             yield return new WaitForSeconds(1);
    10.             maxWait--;
    11.         }
    12.  
    13.         // Stop service and then query
    14.         Input.location.Stop();
    15.  
    16.  
     
  6. Studiomaurer

    Studiomaurer

    Joined:
    Sep 5, 2012
    Posts:
    37
    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.
     
  7. DevMaxima

    DevMaxima

    Joined:
    Jan 24, 2017
    Posts:
    4
    Any update this problem ? :(
    i have same problem in unity 5.5.0p3 , crash on Android device
     
  8. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    111
    Any update on this guys? I'm having the same issue with 5.5.0f3
     
  9. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    111
    I had to switched back to 5.4.2 to fix the crash issue...
     
  10. sanatos0021

    sanatos0021

    Joined:
    Mar 10, 2017
    Posts:
    1
    Hi and it works Or the issue persist?
     
  11. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    111
unityunity