【问题标题】:Can't get GPS working on Moverio bt350 using Unity使用 Unity 无法让 GPS 在 Moverio bt350 上工作
【发布时间】:2018-11-27 11:17:44
【问题描述】:

我正在尝试使用 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();
    }
}

【问题讨论】:

    标签: c# android unity3d epson


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢克里斯。在设备上授予权限,我增加了超时。它只是在初始化时挂起。设备访问 GPS 传感器 - 而不是 wi-fi/蜂窝的谷歌定位
    • 更新:我认为问题在于,用于定位服务状态的 Unity 会自动调用混合 GPS 和网络的“高精度”方法——而仅使用 GPS 的爱普生设备不支持这种方法。如果我禁用网络以使位置更精确,我能够在其他 android 设备上复制该问题。所以我需要了解如何在 Unity 中指定对位置的访问是“仅限设备”GPS 传感器。
    • 嘿,我不知道你还有这个问题,但你应该检查播放器设置中的“低准确度位置”。这仅使用 GPS,但“Input.location.isEnabledByUser”语句虽然在设备中打开,但已被视为错误。如果我删除此语句,则位置给出 '0.0, 0.0' 结果。所以我真的尝试了一切,但找不到解决方案。您能提供任何帮助或建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    • 2011-12-30
    • 2018-03-25
    • 2012-01-18
    • 2016-03-24
    • 1970-01-01
    相关资源
    最近更新 更多