- Home /
Why I can't get GPS information on Android device
Hi!
I just follow the examples of unity, but it doesn't show any message until the waiting time (20 seconds) is out. Is the problem because of mobile phone or my code?
 public class GetLocation : MonoBehaviour
 {
 public GUIText LocationMSG;
 
 IEnumerator Start()
 {
 LocationMSG.text = myText;
 
 // First, check if user has location service enabled
 if (!Input.location.isEnabledByUser)
 {
 yield break;
 }
 
 // Start service before querying location
 Input.location.Start();
 
 // 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)
 {
 // print("Timed out");
 LocationMSG.text = "Time out" ;
 yield break;
 }
 
 // Connection has failed
 if (Input.location.status == LocationServiceStatus.Failed)
 {
 //print("Unable to determine device location");
 LocationMSG.text = "Unable to determine device location";
 yield break;
 }
 else
 {
 LocationMSG.text = "Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " "
 + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp ;
 
 }
 
 // Stop service if there is no need to query location updates continuously
 Input.location.Stop();
 }
 
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
GPS doesn't work in AGPS mode 0 Answers
Radius around GPS location 1 Answer
GPS location on Android 1 Answer
Is it possible to get real world coordinates and use it to trigger event in game? 1 Answer
GPS Application with Unity Android 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                