【发布时间】:2018-11-22 22:12:59
【问题描述】:
我目前正在通过 Unity 开发 ar 游戏。我正在使用 Vuforia sdk 制作游戏。 游戏内需要 GPS 坐标,但不会更新 GPS 坐标。 奇怪的是,在使用gps代码只在屏幕上显示坐标的单个应用程序中,gps坐标是正确更新的,但是如果我将相同的代码放入游戏中,gps坐标在开始时不再更新应用。 我不认为这是代码的问题。请帮忙。
公共类 GPSCheck : MonoBehaviour{
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
IEnumerator Start()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
}
【问题讨论】:
-
你为什么打开一个新问题又问完全相同的问题?