Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator Start()
- {
- // First, check if user has location service enabled
- if (!Input.location.isEnabledByUser)
- {
- ErrorHandler.ShowMessageError("Location service not enabled");
- isLoopAllowed = false;
- yield break;
- }
- // Start service before querying location
- Input.location.Start(Storage.LOCATION_SENSITIVITY, Storage.LOCATION_SENSITIVITY);
- // 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)
- {
- ErrorHandler.ShowMessageError("Timed out");
- isLoopAllowed = false;
- yield break;
- }
- // Connection has failed
- if (Input.location.status == LocationServiceStatus.Failed)
- {
- ErrorHandler.ShowMessageError("Can't locate your device");
- isLoopAllowed = false;
- 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);
- Storage.USER_LATITUDE = Input.location.lastData.latitude;
- Storage.USER_LONGITUDE = Input.location.lastData.longitude;
- Storage.LOCATION_READY = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement