我正在制作一个基于位置的应用程序,该应用程序的罗盘指向一些经纬度坐标。我需要访问自己的坐标,以便能够计算出指南针所需的旋转角度,但是问题是-我的统一位置服务正在超时。此应用的位置敏感度为3米。
我创建了第二个应用程序,它仅向您显示位置坐标为5米的经度和纬度坐标,并且几乎可以立即运行。这是我第一个项目的代码:
IEnumerator Start()
{
// First, check if user has location service enabled
if (!Input.location.isEnabledByUser)
{
ErrorHandler.ShowMessageError("Location service not enabled");
isLoopAllowed = false;
yield break;
}
// Start service before querying location
Input.location.Start(Storage.LOCATION_SENSITIVITY, Storage.LOCATION_SENSITIVITY);
// 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)
{
ErrorHandler.ShowMessageError("Timed out");
isLoopAllowed = false;
yield break;
}
// Connection has failed
if (Input.location.status == LocationServiceStatus.Failed)
{
ErrorHandler.ShowMessageError("Can't locate your device");
isLoopAllowed = false;
yield break;
}
else
{
// Access granted and location value could be retrieved
//print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
Storage.USER_LATITUDE = Input.location.lastData.latitude;
Storage.USER_LONGITUDE = Input.location.lastData.longitude;
Storage.LOCATION_READY = true;
}
}
脚本简介:
isLoopKeyAllowed变量用于在发生错误时停止循环。
存储类只是具有全局变量的类。
ErrorHandler类具有一个称为ShowMessageError()的函数,该函数仅在屏幕上输出错误。
LOCATION_READY是指南针脚本正在使用的变量。
就这样。我不知道出什么问题了。也许是因为灵敏度太高造成的?
(EDIT):问题在于,显示了超时错误,并且循环结束。