using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GPS : MonoBehaviour
{
private string N_Latitude; //经度
private string E_Longitude; //纬度
public Button LocationButton;// 定位按钮
void Start()
{
LocationButton.onClick.AddListener(() =>{
// 这里需要启动一个协同程序
StartCoroutine(StartGPS());
});
}
IEnumerator StartGPS()
{
// Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置
// LocationService.isEnabledByUser 用户设置里的定位服务是否启用
if (!Input.location.isEnabledByUser)
{
// ios需在info.plist添加key:Privacy - Location When In Use Usage Description
Debug.Log("用户没有开启定位权限");
yield break;
} else
{
// LocationService.Start() 启动位置服务的更新,最后一个位置坐标会被使用
// 定位精度10米,最小移动距离10米
Input.location.Start(10.0f, 10.0f);
}
// 不能立刻获得定位,所以需要等待
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing &&
【Unity】使用GPS定位经纬度
最新推荐文章于 2023-06-22 18:07:05 发布