====== 064 位置情報を取得する ====== ===== 概要 ===== 位置情報の取得はInput.location を利用します。 利用するために事前に、端末の設定から位置情報の取得を有効にしておいて下さい。 ==== ソースコード ==== using UnityEngine; using System; using System.Collections; public class LocationManager { // 端末の位置情報が有効化調べる。 public static bool IsEable() { if ( !Input.location.isEnabledByUser ) { Debug.Log("isEnabledByUser --> NO"); return false; } Debug.Log("isEnabledByUser --> OK"); return true; } // 位置情報の取得開始。 public static void Start() { Input.location.Start (); StartWait (); Debug.Log ("service initialize --> success"); } // 位置情報の取得終了。 public static void End() { Input.location.Stop (); Debug.Log ("service finalize --> success"); } // 初期化できるまで待つ static IEnumerator StartWait() { while( Input.location.status == LocationServiceStatus.Initializing ) { yield return new WaitForSeconds(1); } } // 更新処理。 public static void Update() { if ( Input.location.status == LocationServiceStatus.Failed ) { Debug.Log( "Unable to determine device location" ); } else { Debug.Log( "Location: " + " " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.verticalAccuracy + " " + Input.location.lastData.timestamp ); } } }; ==== パラメータの意味 ==== |latitude|緯度| |longitude|経度| |altitude|標高| |horizontalAccuracy|水平精度| |verticalAccuracy|垂直精度| |timestamp|タイムスタンプ|