Unity Input.location is not updating on Android - Galaxy Note 4
I have been trying to detect walking through the GPS location of my galaxy note 4. I am using Input.location to gather the latitude and longitude. My issue is that it only updates on initialization. It never updates again except for random times.
IEnumerator GetLocation ()
{
if (Input.location.status == LocationServiceStatus.Stopped) {
if (!Input.location.isEnabledByUser) {
yield break;
}
// Start service before querying location
Input.location.Start (gpsAccuracy, gpsUpdateInterval);
}
while (Input.location.status != LocationServiceStatus.Running) {
audio.PlayOneShot (dingTone);
yield return new WaitForSeconds (1f);
}
if (Input.location.status == LocationServiceStatus.Failed) {
tm.text = "Location Has Failed";
}
if (Input.location.status == LocationServiceStatus.Running) {
lastPosition = currentPosition;
yield return new WaitForSeconds (0.01f);
currentPosition = new Vector3 (Input.location.lastData.longitude,
0,
Input.location.lastData.latitude);
hasLocation = true;
}
StartCoroutine (GetLocation ());
}
I have set: gpsAccuracy = 1; gpsUpdateInterval = 1;
This is the code I call on start if gps is toggled. I have run numerous checks. It is looping properly, but no matter where I move, it won't update. I have noticed it will have to reset the GPS if I go to the home screen, then back into the app, the GPS updates immediately. Probably because it has to reconfigure.
Answer by LT23Live · Aug 10, 2016 at 07:24 PM
So after doing more research, it didn't work for me because my compass was off. Enable it with,
Input.compass.enabled = true;
The project is working like a charm.