Search Unity

LocationService GPS on iOS throws errors

Discussion in 'iOS and tvOS' started by mole1984, Oct 20, 2018.

  1. mole1984

    mole1984

    Joined:
    Mar 16, 2015
    Posts:
    14
    Hey,
    I´m using LocationService from WIki and it works fine. But logs on iOS (iPhone physical device) show endless times this warning:

    Code (CSharp):
    1. location service updates are not enabled. check locationservice.status before querying last location
    What I´m doing wrong???

    here is my simple script:

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

    ClayBudin

    Joined:
    May 10, 2017
    Posts:
    6
    At what point in your code is the exception being thrown?

    I'm getting the same error, but only intermittently. Usually Location Service is working.

    Thanks,
    Clay Budin
    NYC