Search Unity

Detecting latitude-longitude using gps

Discussion in 'Scripting' started by Soumikbhat, Dec 2, 2014.

  1. Soumikbhat

    Soumikbhat

    Joined:
    Nov 23, 2013
    Posts:
    110
    I saw this code in the unity docs...but cannot make out why is it giving output as :
    0 0 0 0
    Code (CSharp):
    1. public class Position : MonoBehaviour {
    2.  
    3.     // Use this for initialization
    4.     IEnumerator Start() {
    5.         if (!Input.location.isEnabledByUser)
    6.             yield break;
    7.        
    8.         Input.location.Start();
    9.         int maxWait = 20;
    10.         while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
    11.             yield return new WaitForSeconds(1);
    12.             maxWait--;
    13.         }
    14.         if (maxWait < 1) {
    15.             print("Timed out");
    16.             return false;
    17.         }
    18.         if (Input.location.status == LocationServiceStatus.Failed) {
    19.             print("Unable to determine device location");
    20.             return false;
    21.         } else
    22.             print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
    23.         Input.location.Stop();
    24.     }
    25. }
    The doc is this..Don't know why is this not working...
     
  2. Soumikbhat

    Soumikbhat

    Joined:
    Nov 23, 2013
    Posts:
    110
    No one.. ?
     
  3. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    When you get : 0 0 0 0. Is it when you hit play in Editor? If it's the case, it's most of the time the case if you use PC since you can't send any geolocalisation points. Build this for smartphone or tablet and give it a try, it should work.
     
  4. Soumikbhat

    Soumikbhat

    Joined:
    Nov 23, 2013
    Posts:
    110
    Yeah playing it in the editor gives 0 0 0 0...I'll try out in a smartphone or tab maybe..
     
  5. vel77

    vel77

    Joined:
    Jan 5, 2015
    Posts:
    1
    Is
    I am having the same issue and I figured that was the case. Is there way I can test my GPS locations on the PC through other programs ? For example like having BlueStacks (Android Emulator) run my app on the PC and the GPS working in the program like BlueStacks?