【转】通过点击获取地址等信息、可以传值
举例:
百度经纬度:lat=30.52953&lon=120.43016
http://api.map.baidu.com/?qt=rgc&x=13407612.87&y=3550364.78&dis_poi=100&poi_num=10&ie=utf-8&oue=2&res=api&callback=BMap._rd._cbk30352
返回数据:
BMap._rd._cbk30352 && BMap._rd._cbk30352({"content":{"address":"浙江省嘉兴市桐乡市崇德中路47","address_detail":{"city":"嘉兴市","city_code":334,"district":"桐乡市","province":"浙江省","street":"崇德中路","street_number":"47"},"business":"","point":{"x":"13407612.87","y":"3550364.78"},"surround_poi":[{"addr":"崇德中路47","cp":"NavInfo","distance":"26.927155","name":"新华书店崇福店","poiType":"新华书店,图书音像,购物","point":{"x":"13407632.660000","y":"3550346.520000"},"tel":"(0573)88413730","uid":"1c18e2e892e17dabc61b75e4","zip":""},{"addr":"浙江省嘉兴市桐乡市","cp":"NavInfo","distance":"52.717770","name":"光明眼镜崇福店","poiType":"钟表眼镜,购物","point":{"x":"13407575.200000","y":"3550327.900000"},"tel":"","uid":"cde862b70813c6ee9ff779e4","zip":""},{"addr":"崇福镇崇德东路39号","cp":"NavInfo","distance":"56.255920","name":"红太阳KTV娱乐中心","poiType":"KTV,休闲娱乐","point":{"x":"13407668.160000","y":"3550354.400000"},"tel":"(0573)88411218","uid":"ecd5e611cc428d06b72655e4","zip":""},{"addr":"银都中路66号","cp":"NavInfo","distance":"76.699611","name":"金鑫大厦","poiType":"办公大厦,商务大厦","point":{"x":"13407537.350000","y":"3550351.380000"},"tel":"","uid":"0c18663c996927a040ab9ae6","zip":""},{"addr":"银都中路66号","cp":"NavInfo","distance":"76.699611","name":"银都宾馆","poiType":"旅店,宾馆","point":{"x":"13407537.350000","y":"3550351.380000"},"tel":"(0573)88416555","uid":"255234b335f607d3cafa5fe4","zip":""},{"addr":"银都中路66号","cp":"NavInfo","distance":"76.699611","name":"金鑫服饰平价超市","poiType":"服装鞋帽,购物","point":{"x":"13407537.350000","y":"3550351.380000"},"tel":"","uid":"ffc7fafd384596412eb90862","zip":""},{"addr":"崇德中路35号","cp":"NavInfo","distance":"83.651867","name":"崇德百货","poiType":"综合商场\/购物中心,购物","point":{"x":"13407696.440000","y":"3550368.480000"},"tel":"","uid":"b0d64f2939342d808afc0608","zip":""},{"addr":"浙江省嘉兴市桐乡市","cp":"NavInfo","distance":"95.774826","name":"卡尼亚珠宝","poiType":"珠宝饰品,购物","point":{"x":"13407533.050000","y":"3550311.850000"},"tel":"","uid":"a9699f0c58ee9582611c6762","zip":""},{"addr":"桐乡市崇福东路附近","cp":"mix","distance":"95.868714","name":"乔丹专卖","poiType":"服装鞋帽,购物","point":{"x":"13407694.850000","y":"3550414.480000"},"tel":"","uid":"8c539cf8a9cfa740ca09f08f","zip":""}]},"result":{"callback":"BMap._rd._cbk30352","dis_poi":"100","error":0,"ie":"utf-8","little_capacity":[],"oue":"2","poi_num":"10","qt":"rgc","res":"api","type":44,"x":"13407612.87","y":"3550364.78"}})
http://www.bcagps.com/map/json/AddressBMap.ashx?lat=30.52953&lon=120.43016
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>周边最近的POI查询并且解析出中文地址</title> <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script> </head> <body> <div style="width:800px;height:600px;border:1px solid gray;float:left;" id="map"></div> </body> </html> <script type="text/javascript"> var map = new BMap.Map("map"); map.centerAndZoom(new BMap.Point(116.404, 39.915), 16); map.enableScrollWheelZoom(); var geocoder = new BMap.Geocoder(); var locationOptions = { poiRadius: 1500, numPois :2 } map.addEventListener("click", function(e){ var pt = e.point; geocoder.getLocation(pt, function(result){ if (result){ var description = result.address; if (result.surroundingPois[0]){ var poi = result.surroundingPois[0]; description += ". " + poi.title + "向" + getDirDescription(result.point, poi.point) + " " + Math.round(map.getDistance(result.point, poi.point)) + "米. " } if (result.surroundingPois[1]){ var poi = result.surroundingPois[1]; description += "" + poi.title + "向" + getDirDescription(result.point, poi.point) + " " + Math.round(map.getDistance(result.point, poi.point)) + "米." } alert(description); alert("\u53cc\u67aa\u7af9\u6728(\u516c\u53f8\u4f01\u4e1a),\u7af9\u6625\u5802\u5927\u836f\u623f(\u836f\u5e97\/\u836f\u623f,\u533b\u7597)"); } }, locationOptions) }); /** * 获取两点东西南北的位置关系 */ function getDirDescription(pt1, pt2){ var h = pt1.lng - pt2.lng; var v = pt1.lat - pt2.lat; if (Math.abs(h) > Math.abs(v)){ if (h < 0){ return "西"; } else { return "东"; } } else { if (v < 0){ return "南"; } else { return "北"; } } } </script>