Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

LocationService.Start

フィードバック

ありがとうございます

この度はドキュメントの品質向上のためにご意見・ご要望をお寄せいただき、誠にありがとうございます。頂いた内容をドキュメントチームで確認し、必要に応じて修正を致します。

閉じる

送信に失敗しました

なんらかのエラーが発生したため送信が出来ませんでした。しばらく経ってから<a>もう一度送信</a>してください。ドキュメントの品質向上のために時間を割いて頂き誠にありがとうございます。

閉じる

キャンセル

マニュアルに切り替える
public function Start(desiredAccuracyInMeters: float = 10f, updateDistanceInMeters: float = 10f): void;
public void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);
public function Start(desiredAccuracyInMeters: float = 10f, updateDistanceInMeters: float = 10f): void;
public void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);
public function Start(desiredAccuracyInMeters: float = 10f, updateDistanceInMeters: float = 10f): void;
public void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);

パラメーター

説明

ロケーションの更新を開始します。最後の位置座標になります。

Input.location.lastData により取得できます。 サービス開始時にロケーションデータは直ちに送信されません。 現在のサービスステータスを確認するにはコード中で Input.location.status をチェックしてください。 desiredAccuracyInMeters - サービスの精度をメートル単位で指定。 500 メートルなどより高い値に設定することで GPS チップをオンにしておく必要がなくなるため バッテリー容量を節約します。5-10 メートルの値にすることでより精度が得られます。 デフォルトは 10 メートル。 updateDistanceInMeters - Input.location プロパティーが更新されるための最小距離として どれだけ横方向に移動する必要があるかをメートル単位で指定します。 500 メートルなどより高い値にすることでオーバーヘッドが少なくなります。デフォルトは 10 メートルです。

function Start () {
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
            return;
        // Start service before querying location
        Input.location.Start ();
        // Wait until service initializes
        var maxWait : int = 20;
        while (Input.location.status
               == LocationServiceStatus.Initializing && maxWait > 0) {
            yield WaitForSeconds (1);
            maxWait--;
        }
        // Service didn't initialize in 20 seconds
        if (maxWait < 1) {
            print ("Timed out");
            return;
        }
        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed) {
            print ("Unable to determine device location");
            return;
        }
        // Access granted and location value could be retrieved
        else {
            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 ();
    }
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(); } }