我使用的是Unity的GPS系統,並注意到它從未更新過。我不得不關閉應用程序並重新啓動它以獲取當前位置。自動更新GPS位置
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class TestLocationService : MonoBehaviour {
public GameObject longText;
public GameObject latText;
IEnumerator Start() {
Text longitudeText = longText.GetComponent<Text>();
Text latitudeText = latText.GetComponent<Text>();
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) {
print("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed) {
print("Unable to determine device location");
yield break;
} else {
print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
longitudeText.text = "Longitude: " + Input.location.lastData.longitude;
latitudeText.text = "Latitude: " + Input.location.lastData.latitude;
}
Input.location.Stop();
}
}
我希望在自動更新到我目前所在的位置時有一些幫助!提前致謝!
你指望它來更新?你有什麼嘗試? – Jecoms