- Home /
Question by
KristijonasM · May 14, 2016 at 05:24 PM ·
androidlocation
LocationService problems- doesn't show errors.
Hi, i'm trying to creante an app for an android phone, that displays the cordinates. It works, but, if i disable the gps or the program can't get locations- it doesn't show errors in my text field (like "Timed out" or "Unable to determine devite location"). I'm very new to this, so i don't imagine what i'm doing wrong. here's my code.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GetLocation : MonoBehaviour {
public Text textObj;
IEnumerator Start () {
if (!Input.location.isEnabledByUser)
yield break;
Input.location.Start ();
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
yield return new WaitForSeconds (1);
maxWait--;
}
if (maxWait < 1) {
textObj.text = "Timed out";
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed) {
textObj.text ="Unable to determine devite location";
yield break;
} else {
textObj.text ="Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude;
}
Input.location.Stop ();
}
}
Comment