使用Unity无法在Moverio bt350上运行GPS

时间:2018-06-18 14:59:19

标签: c# android unity3d epson

我正在尝试使用Unity在Android 5.1(Lollipop)(Epson moverio BT350 AR眼镜)上获取GPS坐标。

LocationService命令在初始化时挂起。

我使用了Unity在线文档提供的标准代码。

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();
    }
}

1 个答案:

答案 0 :(得分:0)

这可能是您连接设备上的位置服务的权限问题。如果不是这样,我会将超时从20秒增加到你可能没有等待足够长的响应。

    int maxWait = 20; // increase this
    while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
    {
        yield return new WaitForSeconds(1);
        maxWait--;
    }