[高德地图]------- 高德地图通过经纬度获取地址信息代码
作者:互联网
1.高德地图通过经纬度获取地址信息代码 【需要高德Key值】 里面的参数我做改变了 不能暴露自己的位置哈哈哈哈
//原生ajax var fn_Ajax_Get=function(vapi,callback,errer) { //创建XMLHttpRequest var xmlHttp; if (window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ // code for IE6, IE5 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } //监听响应 xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState === 4 && (xmlHttp.status === 200 || xmlHttp.status === 304)) { callback(xmlHttp.responseText); }else{ errer(xmlHttp.responseText); } }; xmlHttp.open("GET",vapi,false); xmlHttp.send(); }; //获取经纬度的地址信息 var fn_get_gd_lng_lat_address=function(v_lng,v_lat,v_key){ var key=""; var address=""; if(v_lng && v_lat){ if(v_key){ key=v_key; } var locationLngLat=v_lng+","+v_lat; var gdUrl="https://restapi.amap.com/v3/geocode/regeo?key={{@key}}&location={{@lnglat}}"; gdUrl=gdUrl.replace("{{@key}}",key).replace("{{@lnglat}}",locationLngLat); fn_Ajax_Get(gdUrl,function (ret) { var retJson=JSON.parse(ret); if(retJson.status=="1") { address = retJson.regeocode.formatted_address; } },function (ret) { }) } return address; }; fn_get_gd_lng_lat_address(116.142421,34.205636,key);
2.得到的数据json
{"status":"1","regeocode":{"addressComponent":{"city":"**市","province":"**省","adcode":"32012","district":"**区","towncode":"3203109000", "streetNumber":{"number":"97号","location":"116.142279,34.205911","direction":"西北","distance":"33.2597","street":"大学路"}, "country":"中国","township":"**街道","businessAreas":[[]],"building":{"name":[],"type":[]},"neighborhood":{"name":[],"type":[]}, "citycode":"0506"},"formatted_address":"**省**市**区铜山街道***大学创业园"},"info":"OK","infocode":"10000"}
1.高德地址:概述-Web服务 API | 高德地图API
标签:xmlHttp,地图,-------,key,address,var,lng,高德 来源: https://blog.csdn.net/qq_38366657/article/details/122413041