C# Can';t使用Unity让GPS在Moverio bt350上工作

C# Can';t使用Unity让GPS在Moverio bt350上工作,c#,android,unity3d,epson,C#,Android,Unity3d,Epson,我正在尝试使用Unity获取Android 5.1(棒棒糖)(Epson moverio BT350 AR眼镜)上的GPS坐标 LocationService命令在初始化时挂起 我使用了Unity在线文档提供的标准代码 using UnityEngine; using System.Collections; public class TestLocationService : MonoBehaviour { IEnumerator Start() { // Fi

我正在尝试使用Unity获取Android 5.1(棒棒糖)(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();
    }
}
使用UnityEngine;
使用系统集合;
公共类TestLocationService:MonoBehavior
{
IEnumerator Start()
{
//首先,检查用户是否启用了位置服务
如果(!Input.location.isEnabledByUser)
屈服断裂;
//在查询位置之前启动服务
Input.location.Start();
//等待服务初始化
int maxWait=20;
while(Input.location.status==LocationServiceStatus.Initializing&&maxWait>0)
{
返回新的WaitForSeconds(1);
maxWait--;
}
//服务在20秒内没有初始化
if(maxWait<1)
{
打印(“超时”);
屈服断裂;
}
//连接失败
if(Input.location.status==LocationServiceStatus.Failed)
{
打印(“无法确定设备位置”);
屈服断裂;
}
其他的
{
//已授予访问权限,无法检索位置值
打印(“位置:“+Input.Location.lastData.latitude+”“+Input.Location.lastData.longitude+”“+Input.Location.lastData.altitude+”“+Input.Location.lastData.HorizontalAccurance+”“+Input.Location.lastData.timestamp”);
}
//如果不需要连续查询位置更新,则停止服务
Input.location.Stop();
}
}

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

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

谢谢你,克里斯。设备上已授予权限,我已增加超时时间。它只是在初始化时挂起。该设备可以访问GPS传感器,而不是使用wi-fi/cellularUPDATE的谷歌定位:我认为问题在于,统一定位服务状态自动要求采用“高精度”方法,将GPS与网络相结合,而爱普生设备不支持这一点,它只使用GPS。如果我禁用网络以使定位更加精确,我就能够在其他android设备上复制这个问题。因此,我需要了解如何在Unity中指定访问位置为“仅限设备”GPS传感器。嘿,我不知道您仍然存在此问题,但您应该从播放器设置中检查“低精度位置”。这只使用GPS,但是“Input.location.isEnabledByUser”语句被认为是错误的,尽管在设备中是打开的。如果我删除此语句,则位置将给出“0.0,0.0”结果。所以我真的什么都试过了,但找不到解决办法。你能给我一些帮助或建议吗?