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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Unity3D GPS獲取玩家地理位置

2019-11-09 18:56:19
字體:
供稿:網(wǎng)友

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 經(jīng)度 /// 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);}

}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 弋阳县| 梁河县| 大荔县| 洛南县| 榆社县| 秦皇岛市| 南通市| 富裕县| 新乡县| 普定县| 宜兴市| 淮滨县| 永善县| 宁夏| 中牟县| 清苑县| 焉耆| 惠州市| 通海县| 阿坝县| 上饶市| 嘉善县| 图木舒克市| 三台县| 磴口县| 安阳县| 浪卡子县| 邹城市| 兴城市| 新邵县| 嘉鱼县| 新干县| 蒙城县| 福建省| 长兴县| 九龙县| 西畴县| 禄丰县| 定边县| 唐海县| 海安县|