国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Unity3D GPS獲取玩家地理位置

2019-11-09 18:08:07
字體:
來源:轉載
供稿:網友

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);}

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沙河市| 北辰区| 沙田区| 杭州市| 朝阳区| 蓬安县| 古丈县| 年辖:市辖区| 宜良县| 梅河口市| 梅河口市| 和静县| 苏尼特左旗| 海兴县| 米脂县| 肃宁县| 清徐县| 涡阳县| 大田县| 万盛区| 嘉善县| 桂东县| 柘城县| 建昌县| 东乡族自治县| 临泽县| 海门市| 吉安市| 沙洋县| 慈利县| 渝北区| 额济纳旗| 宕昌县| 上饶市| 镇沅| 浙江省| 杭锦后旗| 孝感市| 巴中市| 德惠市| 滨海县|