技术标签: c# unity Unity sdk 腾讯地图 逆解析
目录
这段时间在写项目的时候,需要用到GPS逆地址解析,小黑果断就拿出来了之前写的一篇文章Unity之GPS定位(高德),但是经过商量,决定用腾讯地图的SDK腾讯位置服务,于是我们就开始了,也有了这篇文章。
Unity版本: Unity2020.3.13f1c1
命名空间: Newtonsoft.Json
那么,废话不多说,之前每篇博客废话太多,自己都开始嫌弃了。。
第一个脚本:别忘了挂载
public class TencentLocation : MonoBehaviour
{
/// <summary>
/// 获取当前位置及周围信息
/// </summary>
/// <param name="lat">纬度</param>
/// <param name="lng">经度</param>
/// <param name="callback">当前位置信息</param>
/// <returns></returns>
public IEnumerator GetRequest(float lat, float lng, Action<LocationAnalysis> callback)
{
Uri uri = new Uri("https://apis.map.qq.com/ws/geocoder/v1/?location=" + $"{lat},{lng}" + "&key= 你在腾讯官网申请的Key &get_poi=1");
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.Success)
{
System.Object obj = JsonConvert.DeserializeObject(webRequest.downloadHandler.text);
Newtonsoft.Json.Linq.JObject js = obj as Newtonsoft.Json.Linq.JObject;
if (js == null)
yield return null;
callback?.Invoke(js["result"].ToObject<LocationAnalysis>());
}
}
}
}
第二个脚本:这个脚本可花了我不少时间,小黑要赞!
using System.Collections.Generic;
namespace TencentInverseAnalysis
{
/// <summary>
/// 地址解析
/// </summary>
public class LocationAnalysis
{
/// <summary>
/// 经纬度位置
/// </summary>
public Location location { get; set; }
/// <summary>
/// 北京市朝阳区广顺北大街
/// </summary>
public string address { get; set; }
/// <summary>
/// 格式化地址
/// </summary>
public Formatted_addresses formatted_addresses { get; set; }
/// <summary>
/// 地址成分
/// </summary>
public Address_component address_component { get; set; }
/// <summary>
/// 地址信息
/// </summary>
public Ad_info ad_info { get; set; }
/// <summary>
/// 地址参考
/// </summary>
public Address_reference address_reference { get; set; }
/// <summary>
/// 信息点数量
/// </summary>
public int poi_count { get; set; }
/// <summary>
/// 信息点
/// </summary>
public List<PoisItem> pois { get; set; }
}
/// <summary>
/// 经纬度位置
/// </summary>
public class Location
{
/// <summary>
/// 纬度
/// </summary>
public double lat { get; set; }
/// <summary>
/// 经度
/// </summary>
public double lng { get; set; }
}
/// <summary>
/// 格式化后的地址
/// </summary>
public class Formatted_addresses
{
/// <summary>
/// 推荐定位地址
/// </summary>
public string recommend { get; set; }
/// <summary>
/// 粗糙定位地址
/// </summary>
public string rough { get; set; }
}
/// <summary>
/// 地址成分
/// </summary>
public class Address_component
{
/// <summary>
/// 国家
/// </summary>
public string nation { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 市
/// </summary>
public string city { get; set; }
/// <summary>
/// 区
/// </summary>
public string district { get; set; }
/// <summary>
/// 街道
/// </summary>
public string street { get; set; }
/// <summary>
/// 街道号
/// </summary>
public string street_number { get; set; }
}
/// <summary>
/// 地址信息
/// </summary>
public class Ad_info
{
/// <summary>
/// 国家编码
/// </summary>
public string nation_code { get; set; }
/// <summary>
/// 省份编码
/// </summary>
public string adcode { get; set; }
/// <summary>
/// 城市编码
/// </summary>
public string city_code { get; set; }
/// <summary>
/// 位置名
/// </summary>
public string name { get; set; }
/// <summary>
/// 经纬度位置
/// </summary>
public Location location { get; set; }
/// <summary>
/// 国家
/// </summary>
public string nation { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 市
/// </summary>
public string city { get; set; }
/// <summary>
/// 区
/// </summary>
public string district { get; set; }
}
/// <summary>
/// 地址参考
/// </summary>
public class Address_reference
{
/// <summary>
///
/// </summary>
public Street_number street_number { get; set; }
/// <summary>
///
/// </summary>
public Business_area business_area { get; set; }
/// <summary>
///
/// </summary>
public Famous_area famous_area { get; set; }
/// <summary>
///
/// </summary>
public Crossroad crossroad { get; set; }
/// <summary>
///
/// </summary>
public Town town { get; set; }
/// <summary>
///
/// </summary>
public Street street { get; set; }
/// <summary>
///
/// </summary>
public Landmark_l2 landmark_l2 { get; set; }
}
#region 地址参考
/// <summary>
/// 街道号码
/// </summary>
public class Street_number
{
/// <summary>
/// 街道ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 街道台头
/// </summary>
public string title { get; set; }
/// <summary>
/// 街道经纬度位置
/// </summary>
public Location location { get; set; }
/// <summary>
/// 街道据当前距离
/// </summary>
public double _distance { get; set; }
/// <summary>
/// 街道据当前方向
/// </summary>
public string _dir_desc { get; set; }
}
/// <summary>
/// 所在经营范围
/// </summary>
public class Business_area
{
/// <summary>
/// 范围ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 范围台头
/// </summary>
public string title { get; set; }
/// <summary>
/// 范围经纬度
/// </summary>
public Location location { get; set; }
/// <summary>
/// 距离
/// </summary>
public int _distance { get; set; }
/// <summary>
/// 方向
/// </summary>
public string _dir_desc { get; set; }
}
/// <summary>
/// 范围内已注册信息点
/// </summary>
public class Famous_area
{
/// <summary>
/// 店铺ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 店铺台头
/// </summary>
public string title { get; set; }
/// <summary>
/// 店铺位置
/// </summary>
public Location location { get; set; }
/// <summary>
/// 店铺距离
/// </summary>
public int _distance { get; set; }
/// <summary>
/// 店铺方向
/// </summary>
public string _dir_desc { get; set; }
}
/// <summary>
/// 十字路口
/// </summary>
public class Crossroad
{
/// <summary>
/// 十字路口ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 路口台头
/// </summary>
public string title { get; set; }
/// <summary>
/// 路口经纬度位置
/// </summary>
public Location location { get; set; }
/// <summary>
/// 路口据当前位置距离
/// </summary>
public double _distance { get; set; }
/// <summary>
/// 路口据当前位置方向
/// </summary>
public string _dir_desc { get; set; }
}
/// <summary>
/// 区块
/// </summary>
public class Town
{
/// <summary>
/// 区块ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 区块台头
/// </summary>
public string title { get; set; }
/// <summary>
/// 区块位置
/// </summary>
public Location location { get; set; }
/// <summary>
/// 区块据当前位置距离
/// </summary>
public int _distance { get; set; }
/// <summary>
/// 区块据当前位置方向
/// </summary>
public string _dir_desc { get; set; }
}
/// <summary>
/// 街道
/// </summary>
public class Street
{
/// <summary>
/// 街道ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 街道台头
/// </summary>
public string title { get; set; }
/// <summary>
/// 街道经纬度位置信息
/// </summary>
public Location location { get; set; }
/// <summary>
/// 街道据当前位置距离
/// </summary>
public double _distance { get; set; }
/// <summary>
/// 街道据当前位置方向
/// </summary>
public string _dir_desc { get; set; }
}
/// <summary>
/// 地标信息
/// </summary>
public class Landmark_l2
{
/// <summary>
/// 地标ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 地标台头
/// </summary>
public string title { get; set; }
/// <summary>
/// 地标经纬度位置
/// </summary>
public Location location { get; set; }
/// <summary>
/// 地标据当前位置距离
/// </summary>
public int _distance { get; set; }
/// <summary>
/// 地标据当前位置方向
/// </summary>
public string _dir_desc { get; set; }
}
#endregion
/// <summary>
/// 信息点
/// </summary>
public class PoisItem
{
/// <summary>
/// 信息点ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 信息点台头
/// </summary>
public string title { get; set; }
/// <summary>
/// 信息点所在地
/// </summary>
public string address { get; set; }
/// <summary>
/// 信息点种类
/// </summary>
public string category { get; set; }
/// <summary>
/// 信息点经纬度位置
/// </summary>
public Location location { get; set; }
/// <summary>
/// 信息点位置信息
/// </summary>
public Ad_info ad_info { get; set; }
/// <summary>
/// 距离当前经纬度的相对距离
/// </summary>
public int _distance { get; set; }
/// <summary>
/// 据当前位置方向
/// </summary>
public string _dir_desc { get; set; }
}
}
来,让小黑带你去找。
首先打开人家的官网腾讯位置服务 。
然后右上角登录 或者 注册。
完成后,还是点击右上方的控制台。
然后创建一个应用
创建完成后,增加一个key
接着你就有Key值了。然后拿着你的这个key添加到代码中,就ok了。
至此,圆满结束。
- 客官,看完get之后记得点赞哟!
- 小伙伴你还想要别的知识?好的呀,分享给你们
- 小黑的杂货铺,想要什么都有,客官不进来喝杯茶么?
文章浏览阅读2.4w次,点赞115次,收藏255次。计算机组成原理(第三版)唐朔飞-第九章控制单元的功能-课后习题_计算机组成原理唐朔飞第三版答案第九章
文章浏览阅读1.3k次,点赞2次,收藏13次。扩频通信系统仿真完整的代码,方可运行;可提供运行操作视频!适合小白!_扩频matlab代码
文章浏览阅读134次。题目描述题解:题目的描述比较长,理解起来也有一定难度。仔细读题后我们发现整个任务可以分成两个部分:找出咒语机之间所有的升级关系、求最长升级序列。1、求升级关系:容易看出,咒语机i可以抽象成一个图Gi,其顶点集Vi为ni个元件,每个顶点发出两条边——“0”边和“1”边,分别表示将信号加“0”和加“1”。我们枚举两个咒语机A、B(A≠B),判断B是否是A的升级。最简单的...
文章浏览阅读299次。大数据面试题汇总自我介绍hr常问的几道面试题SparkSpark 有什么优缺点?Spark RDD有什么特性kafkaKafka为什么这么快?hbaseHbase系统架构Hbase数据模型HBase vs RDBMSHBase rowkey设计原则HBase 预分区HiveHive order/sort/distribute/cluster by 有什么区别?..._hr能问的大数据面试题
文章浏览阅读312次。Children of the Candy Corn Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13904 Accepted: 6014Description The cornfield maze is a popular Halloween treat. Visitors are shown_nput to this problem will begin with a line containing a single integer n in
文章浏览阅读1.9k次。一、安装xlsxwriter库pip3 install xlsxwriter二、代码import xlsxwriter, osimage = []# 打包前路径:os.path.abspath(__file__)# 打包后路径:os.path.realpath(sys.executable))# 获取文件目录下所有的.png图片def GetImgPathFromFolder(): for root, dirs, files in os.walk(os.path.dirna_python png插入excel
文章浏览阅读3.4k次,点赞2次,收藏10次。报错信息:安装pip install tensorflow==1.15.4的时候遇到了如下报错:ERROR: Could not find a version that satisfies the requirement tensorflow==1.15.4问题分析:如果排除网络问题后,多半就是版本兼容问题了,有几个可能:Tensorflow 和 Python版本匹配:可以参见这篇博客Tensorflow | TF与Keras版本对应,可以看到Tensorflow与Python版本对应,主_error: could not find a version that satisfies the requirement tensorflow==1
文章浏览阅读1.8w次,点赞18次,收藏166次。声明:本博客的内容主要是本人学习其他串口通信博客之后的总结,主要参考的博客地址如下:https://blog.csdn.net/wlk1229/article/details/52566701http://wangbaiyuan.cn/c-serial-communication-write-reading.html#title-0https://blog.csdn.net/super..._c++事件触发读取串口电台
文章浏览阅读1.9w次,点赞7次,收藏61次。Pangolin介绍英文好的直接看github主仓的介绍:https://github.com/stevenlovegrove/PangolinPangolin是一个轻量、便携的管理OpenGl显示、交互和提取的视频输入的快速开发库。其核心是一个简单的OpenGl视口管理器,它能帮助模块化3D可视化,不增加复杂性,提供一个先进且直接的3D导航处理器。Pangolin也提供一个操作程序的机制,这个机制通过配置文件和UI集成,有一个灵活的实时绘图仪,用于可视图形图像数据。穿山甲的宗旨是在不影响性能的前提_pangolin能不能再macos上安装
文章浏览阅读5.9k次,点赞9次,收藏86次。文章目录一、dlib以及opencv-python库安装dlib安装方法:Cmake安装Boost下载安装dlibopencv-python安装方法二、dlib的68点模型三、Python实现人脸识别&表情判别四、参考文章一、dlib以及opencv-python库安装介于我使用的是jupyter notebook,所以在安装dlib和opencv-python时是在这个命令行安装的dlib安装方法:1.若可以,直接使用上图所示命令行输入以下命令:pip install cmakep_face_recognition 口罩识别
文章浏览阅读3k次,点赞12次,收藏28次。不是很熟练,之前从来没用过,讲解不到位恕罪。_c&c++指针实训
文章浏览阅读1.2w次,点赞4次,收藏31次。1)首先新建一个qt工程。在pro文件里面添加 webkitwidgets 和 network模块QT += core gui webkitwidgets networkgreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = html1TEMPLATE = appSOURCES += main.cpp\ _如何将html文件显示到qtdesigner里