Unity 定位
来源:互联网 发布:逐浪cms oracle版 编辑:程序博客网 时间:2024/06/03 21:48
老样子 只说操作
定位的方法:1. 获取经纬度 可以用Unity本身的Input.location。(弊端:性能不强 ,部分手机获取不到,信号不好时获取不到,手机太老获取不到,始终显示状态为:LocationServiceStatus.Initializing)
方法二: 接SDK (我这里接的是高德定位)
先说方法一:
创建脚本:
using UnityEngine;using System.Collections;public class GetGPS : MonoBehaviour{ public string gps_info = ""; 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, 300), this.gps_info); GUI.Label(new Rect(20, 350, 600, 48), this.flash_num.ToString()); GUI.skin.button.fontSize = 50; if (GUI.Button(new Rect(Screen.width / 2 - 110, 200, 220, 85), "GPS定位")) { StartGPS(); } if (GUI.Button(new Rect(Screen.width / 2 - 110, 500, 220, 85), "刷新GPS")) { this.gps_info = " 刷新GPSN:" + Input.location.lastData.latitude + " 刷新GPSE:" + Input.location.lastData.longitude; this.gps_info +=" 状态:" + Input.location.status; this.flash_num += 1; } } //开启定位 void StartGPS() { if (!Input.location.isEnabledByUser) { this.gps_info += "定位没有开启:" + Input.location.isEnabledByUser.ToString(); } else { Input.location.Start(10.0f, 10.0f); this.gps_info += "正在开启定位Start:"; } } //获取定位 void GetUnityGPS() { if (Input.location.status == LocationServiceStatus.Stopped) { this.gps_info="定位服务已经停止"; } else if (Input.location.status == LocationServiceStatus.Initializing) { this.gps_info = " 定位服务正在初始化,在一段时间后,状态会切换回来"; } else if (Input.location.status == LocationServiceStatus.Running) { this.gps_info = "成功定位"; } else if (Input.location.status == LocationServiceStatus.Failed) { this.gps_info = "位置服务失败(用户拒绝访问位置服务)"; } }}方法二:SDK定位
1.获取key (官网上有,关于在发布正式版本的时候要把自己Unity生成的签名key放在C:\Users\Administrator\.android下,然后用控制台的方式输出你的key)
2.获取Jar包(下载高德的一键下载包里 有一个AMapLocation文件 里面只有一个jar包,在eclips编译的时候用(我这里只说的是定位))
3.参考http://blog.csdn.net/u011192809/article/details/52355125?locationNum=3(里面已经说的很详细了可以获取的很全面)
我留了两个测试apk和完整Unity项目
阅读全文
0 0
- unity 定位
- Unity 定位
- unity通过GPS定位
- unity 定位服务GPS API
- 【Unity】使用GPS定位经纬度
- Unity之GPS定位详解
- Unity ios 高德定位
- Unity ios平台GPS地址位置定位
- Unity ios平台GPS地址位置定位
- Unity内部类实现GPS定位
- [Unity] 使用Profiler.BeginSample()定位性能热点
- [Unity] 使用Profiler.BeginSample()定位性能热点
- Unity中快速给Object在屏幕上定位
- unity+高德定位=pokemon go 山寨demo安卓版
- Unity编辑器扩展-ConsoleWindow中的双击日志定位
- Unity编辑器拓展之四:ConsoleWindow中的双击日志定位
- 定位unity在rk3288平台上音频解码无效的bug---定位终成功
- 定位
- chromedriver与chrome版本映射表(更新至v2.33)
- java与mysql的日期类型对应
- bufferevent 设置超时
- EXT getValue()和getRawValue()
- JAVA中堆与栈的区别
- Unity 定位
- vue中echarts3.0自适应
- Android Studio分类整理res/Layout中的布局文件 (笔记4)
- 解决新创建的windows用户无法访问TFS的问题
- JDK性能工具
- solr连接数据库查询
- Spring Cloud--Eureka(一)入门使用
- 阿里云服务器部署分布式hadoop 2.7时,NameNode启动报Problem binding to [master:9000]问题
- 为什么程序员都是夜猫子