<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=(百度APIkey,自己申请)"></script> <input type="text" name="address" value=""/> <script type="text/javascript"> $(function(){ /**百度地图API功能**/ var MapSet = { GetLocation:function(){ var geolocation = new BMap.Geolocation(); geolocation.getCurrentPosition(function(r){ if(this.getStatus() == BMAP_STATUS_SUCCESS){ var rp = new BMap.Point(r.point.lng,r.point.lat); var gc = new BMap.Geocoder(); gc.getLocation(rp,function(rs){ var addComp = rs.addressComponents; $("input[name='address']").val(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber); }); } },{enableHighAccuracy: true}) } }; $(function(){ MapSet.GetLocation(); }); }); </script>
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/websites/article/details/47002401