启动位置服务更新。可能是上次位置坐标。
Retrieved via Input.___location.lastData
.
Service does not start to send ___location data immediately. Code should
check Input.___location.status
for current service status.
desiredAccuracyInMeters - desired service accuracy in meters. Using
higher value like 500 usually does not require to turn GPS chip on and
thus saves battery power. Values like 5-10 could be used for getting
best accuracy. Default value is 10 meters.
updateDistanceInMeters - the minimum distance (measured in meters) a
device must move laterally before Input.___location
property is
updated. Higher values like 500 imply less overhead. Default is 10
meters.
using UnityEngine; using System.Collections;
public class TestLocationService : MonoBehaviour { IEnumerator Start() { // First, check if user has ___location service enabled if (!Input.___location.isEnabledByUser) yield break;
// Start service before querying ___location Input.___location.Start();
// 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) { print("Timed out"); yield break; }
// Connection has failed if (Input.___location.status == LocationServiceStatus.Failed) { print("Unable to determine device ___location"); 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); }
// Stop service if there is no need to query ___location updates continuously Input.___location.Stop(); } }