006-实现Unity3d获取设备的GPS信息(经度纬度信息)
来源:互联网 发布:js中增删数组元素 编辑:程序博客网 时间:2024/04/30 02:56
using UnityEngine;
using System.Collections;
/// <summary>
/// 2016/05/09 获取设备的GPS信息,存储下来,并上传服务器进行验证...
/// </summary>
public class GetGPS : MonoBehaviour
{
public string gps_info = "";//GPS的信息
public int flash_num = 1;//更新的次数
// Use this for initialization
void Start()
{
}
void OnGUI()
{
GUI.skin.label.fontSize = 28;
GUI.Label(new Rect(20, 20, 600, 48), this.gps_info);
GUI.Label(new Rect(20, 50, 600, 48), this.flash_num.ToString());
GUI.skin.button.fontSize = 50;
if (GUI.Button(new Rect(Screen.width / 2 - 110, 200, 220, 85), "GPS定位"))
{
// 这里需要启动一个协同程序
StartCoroutine(StartGPS());
}
if (GUI.Button(new Rect(Screen.width / 2 - 110, 500, 220, 85), "刷新GPS"))
{
this.gps_info = "N:" + Input.location.lastData.latitude + " E:" + Input.location.lastData.longitude;
this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp;
this.flash_num += 1;
}
}
// Input.location = LocationService
// LocationService.lastData = LocationInfo
void StopGPS()
{
Input.location.Stop();
}
IEnumerator StartGPS()
{
// Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置
// LocationService.isEnabledByUser 用户设置里的定位服务是否启用
if (!Input.location.isEnabledByUser)
{
this.gps_info = "isEnabledByUser value is:" + Input.location.isEnabledByUser.ToString() + " Please turn on the GPS";
yield return false;
}
// LocationService.Start() 启动位置服务的更新,最后一个位置坐标会被使用
Input.location.Start(10.0f, 10.0f);
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
// 暂停协同程序的执行(1秒)
yield return new WaitForSeconds(1);
maxWait--;
}
if (maxWait < 1)
{
this.gps_info = "Init GPS service time out";
yield return false;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
this.gps_info = "Unable to determine device location";
yield return false;
}
else
{
this.gps_info = "N:" + Input.location.lastData.latitude + " E:" + Input.location.lastData.longitude;
this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp;
yield return new WaitForSeconds(100);
}
}
}
using System.Collections;
/// <summary>
/// 2016/05/09 获取设备的GPS信息,存储下来,并上传服务器进行验证...
/// </summary>
public class GetGPS : MonoBehaviour
{
public string gps_info = "";//GPS的信息
public int flash_num = 1;//更新的次数
// Use this for initialization
void Start()
{
}
void OnGUI()
{
GUI.skin.label.fontSize = 28;
GUI.Label(new Rect(20, 20, 600, 48), this.gps_info);
GUI.Label(new Rect(20, 50, 600, 48), this.flash_num.ToString());
GUI.skin.button.fontSize = 50;
if (GUI.Button(new Rect(Screen.width / 2 - 110, 200, 220, 85), "GPS定位"))
{
// 这里需要启动一个协同程序
StartCoroutine(StartGPS());
}
if (GUI.Button(new Rect(Screen.width / 2 - 110, 500, 220, 85), "刷新GPS"))
{
this.gps_info = "N:" + Input.location.lastData.latitude + " E:" + Input.location.lastData.longitude;
this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp;
this.flash_num += 1;
}
}
// Input.location = LocationService
// LocationService.lastData = LocationInfo
void StopGPS()
{
Input.location.Stop();
}
IEnumerator StartGPS()
{
// Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置
// LocationService.isEnabledByUser 用户设置里的定位服务是否启用
if (!Input.location.isEnabledByUser)
{
this.gps_info = "isEnabledByUser value is:" + Input.location.isEnabledByUser.ToString() + " Please turn on the GPS";
yield return false;
}
// LocationService.Start() 启动位置服务的更新,最后一个位置坐标会被使用
Input.location.Start(10.0f, 10.0f);
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
// 暂停协同程序的执行(1秒)
yield return new WaitForSeconds(1);
maxWait--;
}
if (maxWait < 1)
{
this.gps_info = "Init GPS service time out";
yield return false;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
this.gps_info = "Unable to determine device location";
yield return false;
}
else
{
this.gps_info = "N:" + Input.location.lastData.latitude + " E:" + Input.location.lastData.longitude;
this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp;
yield return new WaitForSeconds(100);
}
}
}
0 0
- 006-实现Unity3d获取设备的GPS信息(经度纬度信息)
- GPS获取当前的经度和纬度
- unity 获取设备的GPS信息
- Unity3d,获取GPS定位信息
- 凨-百度地图API之地图标注(JS版),地理位置信息,根据地址获取经度纬度
- Android 获取地理位置的经度和纬度
- Android 获取地理位置的经度和纬度
- Android 获取地理位置的经度和纬度
- GPS 经度纬度 坐标转换的以色列横轴墨卡托投影(ITM)
- 通过经度、纬度获取地址名称[JS实现]
- google地图获取经度、纬度
- google地图获取经度、纬度
- Android获取经度和纬度
- 根据地址获取经度纬度
- 根据地址获取经度纬度
- SQL通过经度和纬度(已知的一个点)来查询方圆4km内符合条件的信息
- Android 自带 获取地理位置的经度和纬度
- 腾讯地图获取地址的经度和纬度
- hdoj-5301-Buildings
- redux-async-connect
- Spark名词解释
- iMAC——关闭自动弹出手机照片
- 内存带宽测试-STREAM的使用
- 006-实现Unity3d获取设备的GPS信息(经度纬度信息)
- mysql 1615 Prepared statement needs to be re-prepared
- 7. Reverse Integer
- IOS 连接(浏览器)唤醒应用 openURL 回调不走
- 使用Opencv的一些注意事项
- 2.mybatis框架原理与搭建流程
- Android开发学习总结(四)——Eclipse在线安装ADT插件
- HIVE中insert into 和overwrite的用法--转载
- iOS9新特性之常见关键字