1.首先要在HTML页面引入
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=rKF3HrkL8UIRSvXs7OIsnMH9RbflSsdT"></script>
2. 在js中写入方法
var address = '';
//百度地图定位
function baiduMapPos() {
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r) {
if(this.getStatus() == BMAP_STATUS_SUCCESS) {
var point = new BMap.Point(r.point.lng, r.point.lat); //用所定位的经纬度查找所在地省市街道等信息
var gc = new BMap.Geocoder();
gc.getLocation(point, function(rs) {
address = rs.address;
alert(address);
});
} else {
address = 'fail';
mui.alert('定位失败');
}
}, {
enableHighAccuracy: true
})
}