如何获得统一3d中的GPS坐标

时间:2016-04-16 09:58:25

标签: c# android unity3d gps

我得到了这个代码来获取GPS坐标但不知何故我只得到了相同坐标的输出。我不会改变输出,有时我的纬度为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";
    }



}

1 个答案:

答案 0 :(得分:1)

如果您确定GPS已启用且代码中没有任何运行时错误,则可能是您正在测试的方式。

Input.location.Start()方法具有要更新的默认距离值。默认情况下,它有10米,因此你需要走10米才能看到变化。在初始化时更改这些值。

Input.location.Start(10,0.1f); //准确度,每0.1米