簡體   English   中英

如何在統一3D中獲取GPS坐標

[英]How to get GPS coordinates in unity 3d

我得到了用於獲取GPS坐標的代碼,但是以某種方式我只得到了相同坐標的輸出。 IT不會更改輸出,有時我的緯度為0,經度為0,請有人幫助我或有人具有獲取坐標的語法

using UnityEngine;
using System.Collections;
using UnityEngine.UI;


public class testlocation : MonoBehaviour {

    public void Start()
    {

        // turn on location services, if available 
        Input.location.Start();
    }

    public void Update()
    {
        Text singleText = GameObject.Find("SinglePlayerButton").GetComponentInChildren<Text>();

        //Do nothing if location services are not available
        if (Input.location.isEnabledByUser)
        {
            float lat = Input.location.lastData.latitude;
            float lon = Input.location.lastData.longitude;



            singleText.text = "Depart lat: " + lat + "lon: " + lon;

        }
        else
            singleText.text = "gps off";
    }



}

如果您確定GPS已啟用,並且代碼中沒有任何運行時錯誤,則可能是您進行測試的方式。

Input.location.Start()方法具有要更新的默認距離值。 默認情況下,它有10m,因此您需要步行10m才能看到更改。 在初始化時更改這些值。

Input.location.Start(10,0.1f); //精度,每0.1m

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM