如何通过使用Unity获得纬度和经度值的精度?

时间:2018-10-29 08:57:55

标签: unity3d gps arkit indoor-positioning-system

嗨,我正在使用下面的代码来获取IOS设备的经度和纬度,问题是我最多只能得到4点,所以我在博客中读到我们需要使用double来获得更多的小数点和Unity API仅支持4个小数点或最多6个小数点的纬度。为了获得准确的纬度/经度值,我们需要更多的小数点(例如:8.8382738239232032,120.23232328347823782782)。如何获取更多的小数点。

void Start ()
{
    StartCoroutine(Getdata());
}



IEnumerator Getdata()
{
    // 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
{




    double aa= Input.location.lastData.latitude;
    Debug.Log("Double Latitude="+aa);

    latitudes = double.Parse(Input.location.lastData.latitude.ToString("R"));
    longitudes = double.Parse(Input.location.lastData.longitude.ToString("R"));
    altitudes = double.Parse(Input.location.lastData.altitude.ToString("R"));
    deviceinfo = SystemInfo.deviceModel;
// Access granted and location value could be retrieved
Locationinformation.text = "Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp;
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 :(得分:1)

我在这里知道2种选择: 要么使用像这样的其他资产accura-gps-for-unity 或获取在iPhone_Sensors.mm中拾取的值,然后将它们转换为字符串,最后将它们传递给Unity。使用此GUID PluginsForIOS