<script src="http://api.map.baidu.com/api?v=2.0&ak=s6vFvPKgaEnI2ImqBpKGDj0m"></script> <script src="http://api.map.baidu.com/getscript?v=2.0&ak=s6vFvPKgaEnI2ImqBpKGDj0m&services=&t=20160401164342"></script> <div id="allmap"></div> <script> var cid = 35; var geolocation = new BMap.Geolocation(); geolocation.getCurrentPosition(function(r){ if(this.getStatus() == BMAP_STATUS_SUCCESS){ var position = { lng: r.point.lng, lat: r.point.lat } if(cid == ‘sort‘){ sort(position); } else { positions(position, cid); } //alert(‘您的位置:‘+r.point.lng+‘,‘+r.point.lat); $("#poi").val(r.point.lng+‘,‘+r.point.lat); getAddress(r.point.lng,r.point.lat); } else { alert(‘获取当前位置失败,请确定您开启了定位服务‘); } },{enableHighAccuracy: true}); //该js函数是必须要的不然要报错 function positions(json, cid) {} //根据经纬度获取具体地址信息 function getAddress(lng,lat){ var map = new BMap.Map("allmap"); var point = new BMap.Point(lng,lat); map.centerAndZoom(point,12); var geoc = new BMap.Geocoder(); geoc.getLocation(point,function(rs){ var addComp = rs.addressComponents; var names=""; for(var name in addComp){ names+=name+": "+addComp[name]+", "; } // alert(names); //alert(addComp.province + "," + addComp.city + "," + addComp.district + "," + addComp.street + "," + addComp.streetNumber); $("#area").val(addComp.province + "," + addComp.city + "," + addComp.district); $("#addr").val(addComp.street + "," + addComp.streetNumber); getWeather(addComp.city); }); } function getWeather(citytq) { $.ajax({ async: false, type: "GET", url: "http://wthrcdn.etouch.cn/weather_mini?city="+citytq, success: function (res) { alert(res); } }); } </script>
原文地址:https://www.cnblogs.com/kccdzz/p/9761542.html
时间: 2024-10-24 01:15:52