百度地图定位,获取省市区
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="jquery.min.js"></script> <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=v"></script> </head> <body> <div id="allmap"></div> </body> <script type="text/javascript"> $(function () { var geolocation = new BMap.Geolocation(); var gc = new BMap.Geocoder(); geolocation.getCurrentPosition(function (r) { console.log(r); if (this.getStatus() == BMAP_STATUS_SUCCESS) { var pt = r.point; gc.getLocation(pt, function (rs) { var addComp = rs.addressComponents; var province = addComp.province; var city = addComp.city; var area = addComp.district; alert(province+":"+city+":"+area); }); } else { alert("定位失败"); } }, { enableHighAccuracy: true }); }); //获取地里位置 End </script> </html>