So I have a Android Lollipop 6.0.1. I have gone through the tutorials to make it work with accelerometer, gyro and compass. All of which work. However it always seems to think that the GPS on my phone is not enabled even though it is.
This is the same after I compile it it and install it on the phone and if a try to run it through Unity Remote 5.
Am I missing an extra setting? My GPS Location is turned on on my phone and it works with other phone apps. Just not the Unity ones that I’m trying to create. I’m just trying to get simple latitude and longitude data
The code I am using is below. I only get to the point in the code !Input.location.isEnabledByUser and it kicks me out with the Debug.Log “user has not enabled gps”
Thanks All, hope you can help.
using UnityEngine;
using System.Collections;
using System;
public class GPS : MonoBehaviour {
public static GPS Instance { set; get; }
public float latitude;
public float longitude;
private void Start()
{
Instance = this;
DontDestroyOnLoad(gameObject);
StartCoroutine(StartLocationService());
}
private IEnumerator StartLocationService()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("user has not enabled gps");
yield break;
}
Input.location.Start();
int maxWait = 20;
while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return new WaitForSeconds(1);
maxWait--;
}
if (maxWait <= 0)
{
Debug.Log("Timed Out");
yield break;
}
if(Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to dtermine device location");
yield break;
}
latitude = Input.location.lastData.latitude;
longitude = Input.location.lastData.longitude;
yield break;
}
}