无需接入SDK即可在Unity中获取经纬度(Android/iOS),告诉我你的坐标
发布日期:2021-06-30 19:35:20
浏览次数:3
分类:技术文章
本文共 1818 字,大约阅读时间需要 6 分钟。
Unity获取经纬度
Unity提供了Input.location,方便我们获取经纬度。不过,只能获取经纬度,如果想要通过经纬度得出具体省份城市,则需要通过SDK接口了。
测试结果
场景如下
测试结果如下代码
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class Main : MonoBehaviour { public Text infoText; public Button getLocationBtn; void Start() { getLocationBtn.onClick.AddListener (() => { StartCoroutine (StartLocate ()); }); } IEnumerator StartLocate() { if (!Input.location.isEnabledByUser) { Input.location.Start(); infoText.text = "false == location.isEnabledByUser"; yield break; } // Start service before querying location Input.location.Start(); // Wait until service initializes int maxWait = 20; while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) { yield return new WaitForSeconds(1); maxWait--; } // Service didn't initialize in 20 seconds if (maxWait < 1) { var logStr = "Timed out"; infoText.text = logStr; Debug.Log (logStr); yield break; } // Connection has failed if (Input.location.status == LocationServiceStatus.Failed) { var logStr = "Unable to determine device location"; infoText.text = logStr; Debug.Log (logStr); yield break; } else { // Access granted and location value could be retrieved var logStr = "Location, 纬度: " + Input.location.lastData.latitude + ",经度: " + Input.location.lastData.longitude + ",高度: " + Input.location.lastData.altitude + "\n水平精确度: " + Input.location.lastData.horizontalAccuracy + ",时间戳: " + Input.location.lastData.timestamp; infoText.text = logStr; Debug.Log (logStr); //取出位置的经纬度 string str = Input.location.lastData.longitude + "," + Input.location.lastData.latitude; } // Stop service if there is no need to query location updates continuously Input.location.Stop(); }}
转载地址:https://linxinfa.blog.csdn.net/article/details/107523164 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月05日 17时03分04秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
目标检测神经网络的发展历程(52 个目标检测模型)
2019-04-30
Boundary loss 损失函数
2019-04-30
tensorflow使用tensorboard进行可视化
2019-04-30
凸优化 convex optimization
2019-04-30
数据库索引 & 为什么要对数据库建立索引 / 数据库建立索引为什么会加快查询速度
2019-04-30
IEEE与APA引用格式
2019-04-30
research gap
2019-04-30
pytorch训练cifar10数据集查看各个种类图片的准确率
2019-04-30
Python鼠标点击图片,获取点击点的像素坐标
2019-04-30
路径规划(一) —— 环境描述(Grid Map & Feature Map) & 全局路径规划(最优路径规划(Dijkstra&A*star) & 概率路径规划(PRM&RRT))
2019-04-30
RRT算法(快速拓展随机树)的Python实现
2019-04-30
D*算法
2019-04-30
强化学习(四) —— Actor-Critic演员评论家 & code
2019-04-30
RESTful API
2019-04-30
优化算法(四)——粒子群优化算法(PSO)
2019-04-30