如何在unity 3d中获取GPS坐标
本文关键字:获取 GPS 坐标 3d unity | 更新日期: 2024-09-21 11:02:02
我得到了这个获取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";
}
}
如果您确定GPS已启用,并且代码中没有任何运行时错误,那么这可能是您的测试方式。
Input.location.Start()方法有一个要更新的默认距离值。默认情况下它有10米,因此你需要走10米才能看到变化。在初始化时更改这些值。
输入位置启动(10,0.1f);//精度,每0.1m