その後のその後

iOSエンジニア 堤 修一のブログ github.com/shu223

Unity での位置情報の取得方法

Input クラスの location というプロパティを利用します。
http://unity3d.com/support/documentation/ScriptReference/Input-location.html

Property for accessing device location


こんな感じで位置情報をとれるようです。
※Unity オフィシャルサイトのリファレンスページのサンプルコードを転載しています。

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.latitude + " " +
               Input.location.longitude + " " +
               Input.location.altitude + " " +
               Input.location.horizontalAccuracy + " " +
               Input.location.timestamp);
    }

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

位置情報取得を開始しつつ、1秒ごとにポーリングしながら最大20秒待ち、位置情報がとれたら取得をストップ、というコードになっています。


リファレンスでたまたま発見しただけでまだ試せていないのですが、
後々必要になることもありそうなので書いておきました。