Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. IEnumerator Start()
  2. {
  3. // First, check if user has location service enabled
  4. if (!Input.location.isEnabledByUser)
  5. {
  6. ErrorHandler.ShowMessageError("Location service not enabled");
  7. isLoopAllowed = false;
  8. yield break;
  9. }
  10.  
  11. // Start service before querying location
  12. Input.location.Start(Storage.LOCATION_SENSITIVITY, Storage.LOCATION_SENSITIVITY);
  13.  
  14. // Wait until service initializes
  15. int maxWait = 20;
  16. while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
  17. {
  18. yield return new WaitForSeconds(1);
  19. maxWait--;
  20. }
  21.  
  22. // Service didn't initialize in 20 seconds
  23. if (maxWait < 1)
  24. {
  25. ErrorHandler.ShowMessageError("Timed out");
  26. isLoopAllowed = false;
  27. yield break;
  28. }
  29.  
  30. // Connection has failed
  31. if (Input.location.status == LocationServiceStatus.Failed)
  32. {
  33. ErrorHandler.ShowMessageError("Can't locate your device");
  34. isLoopAllowed = false;
  35. yield break;
  36. }
  37. else
  38. {
  39. // Access granted and location value could be retrieved
  40. //print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
  41. Storage.USER_LATITUDE = Input.location.lastData.latitude;
  42. Storage.USER_LONGITUDE = Input.location.lastData.longitude;
  43. Storage.LOCATION_READY = true;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement