Version: 2021.3
言語: 日本語
public void Start ();
public void Start (float desiredAccuracyInMeters);
public void Start (float desiredAccuracyInMeters, float updateDistanceInMeters);

パラメーター

desiredAccuracyInMeters The service accuracy you want to use, in meters. This determines the accuracy of the device's last ___location coordinates. Higher values like 500 don't require the device to use its GPS chip and thus save battery power. Lower values like 5-10 provide the best accuracy but require the GPS chip and thus use more battery power. The default value is 10 meters.
updateDistanceInMeters The minimum distance, in meters, that the device must move laterally before Unity updates Input.___location. Higher values like 500 produce fewer updates and are less resource intensive to process. The default is 10 meters.

説明

Starts ___location service updates.

After you call this function, you can access the device's last ___location coordinates. To do this, check lastData in Input.___location.

Note: The ___location service doesn't start to send ___location data immediately. Check status in Input.___location for the current service status.

On Android, using this method in a scripts automatically adds the ACCESS_FINE_LOCATION permission to the android manifest. If you use low accuracy values like 500 or higher, you can select Low Accuracy Location in Player Settings to add the ACCESS_COARSE_LOCATION permission instead.

using UnityEngine;
using System.Collections;

public class TestLocationService : MonoBehaviour { IEnumerator Start() { // Check if the user has ___location service enabled. if (!Input.___location.isEnabledByUser) yield break;

// Starts the ___location service. Input.___location.Start();

// Waits until the ___location service initializes int maxWait = 20; while (Input.___location.status == LocationServiceStatus.Initializing && maxWait > 0) { yield return new WaitForSeconds(1); maxWait--; }

// If the service didn't initialize in 20 seconds this cancels ___location service use. if (maxWait < 1) { print("Timed out"); yield break; }

// If the connection failed this cancels ___location service use. if (Input.___location.status == LocationServiceStatus.Failed) { print("Unable to determine device ___location"); yield break; } else { // If the connection succeeded, this retrieves the device's current ___location and displays it in the Console window. print("Location: " + Input.___location.lastData.latitude + " " + Input.___location.lastData.longitude + " " + Input.___location.lastData.altitude + " " + Input.___location.lastData.horizontalAccuracy + " " + Input.___location.lastData.timestamp); }

// Stops the ___location service if there is no need to query ___location updates continuously. Input.___location.Stop(); } }