腾讯地图逆地址解析,通过经纬度获取详细的信息数据
根据腾讯地图API,以图文的方式一步一步的来说明如何获取详细的位置信息数据。具体参考腾讯地图Webservice API的简介。腾讯地图WebService API
第一步:申请开发者密钥(key)申请密钥
我选择的应用类型为浏览器类型(调用Javascript API、JSONP调用WebService API、静态图API等)。
填写完成提交好既可以获取属于自己的Key。
第二步:Key获取到了,下面就要通过ajax请求获取位置信息了
首先跟大家说一下此接口都可以获取那些信息,以及需要传哪些参数。简单来说就是输入坐标返回地理位置信息和附近poi列表(POI是“Point of Interest”的缩写,可以翻译成“信息点”,每个POI包含四方面信息,名称、类别、经度纬度、附近的酒店饭店商铺等信息)。
{
"status": 0,
"message": "query ok",
"result": {
"location": {
"lat": 39.984154,
"lng": 116.30749
},
"address": "北京市海淀区彩和坊路北四环西路66号",
"formatted_addresses": {
"recommend": "海淀区北四环西路66号中国技术交易大厦内",
"rough": "海淀区中关村"
},
"address_component": {
"nation": "中国",
"province": "北京市",
"city": "北京市",
"district": "海淀区",
"street": "彩和坊路",
"street_number": "北四环西路66号"
},
"ad_info": {
"adcode": "110108",
"name": "中国,北京市,北京市,海淀区",
"location": {
"lat": 39.984154,
"lng": 116.307487
},
"nation": "中国",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"address_reference": {
"crossroad": {
"title": "彩和坊路/北四环西路辅路(路口)",
"location": {
"lat": 39.985001,
"lng": 116.308113
},
"_distance": 104.2,
"_dir_desc": "西南"
},
"street": {
"title": "彩和坊路",
"location": {
"lat": 39.984154,
"lng": 116.308098
},
"_distance": 49.1,
"_dir_desc": "西"
},
"famous_area": {
"title": "中关村",
"location": {
"lat": 39.984119,
"lng": 116.307503
},
"_distance": 0,
"_dir_desc": "内"
},
"town": {
"title": "海淀街道",
"location": {
"lat": 39.984154,
"lng": 116.307487
},
"_distance": 0,
"_dir_desc": "内"
},
"street_number": {
"title": "北四环西路66号",
"location": {
"lat": 39.984119,
"lng": 116.307503
},
"_distance": 0,
"_dir_desc": ""
},
"landmark_l2": {
"title": "中国技术交易大厦",
"location": {
"lat": 39.984154,
"lng": 116.307487
},
"_distance": 0,
"_dir_desc": "内"
}
},
"poi_count": 10,
"pois": [
{
"id": "3629720141162880123",
"title": "中国技术交易大厦",
"address": "北四环西路66号",
"category": "房产小区;商务楼宇",
"location": {
"lat": 39.984154,
"lng": 116.307487
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 0,
"_dir_desc": "内"
},
{
"id": "12925244666643621769",
"title": "中国技术交易大厦B座",
"address": "北京市海淀区北四环西路66号",
"category": "房产小区;商务楼宇",
"location": {
"lat": 39.984112,
"lng": 116.307587
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 9.7,
"_dir_desc": ""
},
{
"id": "2845372667492951071",
"title": "中国技术交易大厦A座",
"address": "北京市海淀区北四环西路66号中国技术交易大厦",
"category": "房产小区;商务楼宇",
"location": {
"lat": 39.984112,
"lng": 116.307587
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 9.7,
"_dir_desc": ""
},
{
"id": "12017569646070509084",
"title": "中关村SOHOA区",
"address": "北京市海淀区海淀北二街8号中关村SOHO",
"category": "房产小区;商务楼宇",
"location": {
"lat": 39.983452,
"lng": 116.310143
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 239.6,
"_dir_desc": "西"
},
{
"id": "206863847875503767",
"title": "中关村SOHOB区",
"address": "北京市海淀区海淀北二街8号",
"category": "房产小区;商务楼宇",
"location": {
"lat": 39.983452,
"lng": 116.310143
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 239.6,
"_dir_desc": "西"
},
{
"id": "2586789338541507151",
"title": "大恒科技大厦南座",
"address": "北京市海淀区苏州街3号",
"category": "房产小区;商务楼宇",
"location": {
"lat": 39.9827,
"lng": 116.305359
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 243.2,
"_dir_desc": "东北"
},
{
"id": "10411172112248966185",
"title": "大恒科技大厦北座",
"address": "北京市海淀区苏州街3号",
"category": "房产小区;商务楼宇",
"location": {
"lat": 39.982422,
"lng": 116.305313
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 267.5,
"_dir_desc": "东北"
},
{
"id": "3467897955375836486",
"title": "西屋国际A座",
"address": "北京市海淀区苏州街12号",
"category": "房产小区;住宅区;住宅小区",
"location": {
"lat": 39.98093,
"lng": 116.30658
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 367.1,
"_dir_desc": "东北"
},
{
"id": "10159988224873792278",
"title": "西屋国际F座",
"address": "北京市海淀区苏州街12号",
"category": "房产小区;住宅区;住宅小区",
"location": {
"lat": 39.980793,
"lng": 116.307381
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 374.2,
"_dir_desc": "东北"
},
{
"id": "1833965334134367830",
"title": "西屋国际B座",
"address": "北京市海淀区苏州街12号",
"category": "房产小区;住宅区;住宅小区",
"location": {
"lat": 39.980759,
"lng": 116.306427
},
"ad_info": {
"adcode": "110108",
"province": "北京市",
"city": "北京市",
"district": "海淀区"
},
"_distance": 388.6,
"_dir_desc": "东北"
}
]
}
}
以上就是返回的参数信息,具体的参数介绍:http://lbs.qq.com/webservice_v1/guide-gcoder.html
下面呢,就写一下如何发送ajxa请求,当然这个请求是jsonp的跨域请求。
var data={
location:"39.984154,116.307490",
/*换成自己申请的key*/
key:"OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77",
get_poi:0
}
var url="http://apis.map.qq.com/ws/geocoder/v1/?";
data.output="jsonp";
$.ajax({
type:"get",
dataType:'jsonp',
data:data,
jsonp:"callback",
jsonpCallback:"QQmap",
url:url,
success:function(json){
/*json对象转为文本 var aToStr=JSON.stringify(a);*/
var toStr = JSON.stringify(json);
toStr=getFormatJsonStrFromString(toStr);
/*调用业务处理程序*/
suggestion_example&&suggestion_example($show,url_list,toStr);
},
error : function(err){alert("服务端错误,请刷新浏览器后重试")}
}
这样在跨域得到的数据就可以在ajax请求的【json】中获取了。
信息来源:https://www.cnblogs.com/benefitworld/p/5328420.html
本文由 我爱PHP169 作者:admin 发表,其版权均为 我爱PHP169 所有,文章内容系作者个人观点,不代表 我爱PHP169 对观点赞同或支持。如需转载,请注明文章来源。