Unity3D GPS获取玩家地理位置
来源:互联网 发布:需要文章源码怎么写 编辑:程序博客网 时间:2024/05/29 18:46
using UnityEngine;
using System.Collections;
public enum LocationError
{
ERROR_NONE, //没有错误
ERROR_NOT_ENABLED, //GPS未启用
ERROR_TIMEOUT, //请求超时
ERROR_FAILED, //请求失败
}
public class LocationInfo
{
///
/// Geographical device location latitude. 纬度
///
public float latitude;
///
/// Geographical device location longitude 经度
///
public float longitude;
///
/// Geographical device location altitude
///
public float altitude;
///
/// Horizontal accuracy of the location.
///
public float horizontalAccuracy;
///
/// Vertical accuracy of the location.
///
public float verticalAccuracy;
///
/// Timestamp (in seconds since 1970) when location was last time updated
///
public double timestamp;
public string error = null;public LocationError errcode = LocationError.ERROR_NONE;
}
public class LocationHelp : MonoBehaviour {
public static LocationHelp _instance=null;public static LocationHelp Instance{ get { return _instance; }}void Awake(){ _instance = this;}public delegate void GetLocationCallback(LocationInfo location);public static GetLocationCallback GetUserLocation;public void GetLocation(GetLocationCallback callback){ StartCoroutine(GetGPS(callback));}IEnumerator GetGPS(GetLocationCallback callback){ LocationInfo info = new LocationInfo(); if (!Input.location.isEnabledByUser) { info.errcode = LocationError.ERROR_NOT_ENABLED; info.error = "用户未开启GPS"; Debug.Log("用户未开启GPS"); callback(info); yield break; } // Input.location.Start(); Input.location.Start(5.0f, 5.0f); int maxWait = 5; while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) { yield return new WaitForSeconds(1); maxWait--; } if (maxWait < 1) { info.errcode = LocationError.ERROR_TIMEOUT; info.error = "获取GPS信息超时"; Debug.Log("获取GPS信息超时"); callback(info); yield break; } if(Input.location.status == LocationServiceStatus.Failed) { info.errcode = LocationError.ERROR_FAILED; info.error = "获取GPS信息失败"; Debug.Log("获取GPS信息失败"); callback(info); yield break; } info.latitude = Input.location.lastData.latitude; info.longitude = Input.location.lastData.longitude; info.altitude = Input.location.lastData.altitude; info.horizontalAccuracy = Input.location.lastData.horizontalAccuracy; info.verticalAccuracy = Input.location.lastData.verticalAccuracy; info.timestamp = Input.location.lastData.timestamp; callback(info);}
}
- Unity3D GPS获取玩家地理位置
- Android GPS获取地理位置
- GPS获取地理位置
- Android GPS获取地理位置代码
- 【Unity】unity3d 获取手机地理位置
- Unity3d获取GPS 经纬度
- Android 使用GPS获取当前地理位置
- 使用LocationManager获取GPS地理位置信息
- Android GPS获取地理位置并计算距离
- Android APP - GPS定位并获取地理位置
- 安卓获取gps地理位置信息
- windows phone获取GPS地理位置信息
- Unity3d,获取GPS定位信息
- 根据GPS获得的经纬度来获取地理位置信息
- android 通过GPS获取用户地理位置并监听位置变化
- android 通过GPS获取用户地理位置并监听位置变化
- android 通过GPS获取用户地理位置并监听位置变化
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation)
- SNMP网络管理协议
- JS之面向对象
- 自建 webapi rest
- CentOS7 Zookeeper3.4.9集群部署
- LNMP(linux+nginx+mysql+php)网站服务器架构
- Unity3D GPS获取玩家地理位置
- RecyclerView简单使用
- CentOS安装配置Mycat+mysql水平分割,实现分布式存储
- Spring的代理模式(静态代理和动态代理)
- EasyUi Tree 控件的State属性
- .NET 发布网站步骤
- YouTube推荐算法原理
- 常见数据挖掘面试题
- 经纬度两点之间的距离计算