function BMapTools(BMap) {
|
this.geolocation = new BMap.Geolocation();
|
this.geoc = new BMap.Geocoder();
|
this.convertor = new BMap.Convertor();
|
}
|
|
// 获取当前浏览器所在地址的经纬度
|
BMapTools.prototype.getPoint = function(callback) {
|
let geolocation = this.geolocation;
|
geolocation.getCurrentPosition(function(r){
|
if(this.getStatus() == BMAP_STATUS_SUCCESS){
|
if(typeof callback == 'function') {
|
callback(r);
|
}
|
}else {
|
console.log('failed' + this.getStatus());
|
}
|
});
|
};
|
|
// 根据经纬度逆地址解析出省-市-区/县
|
BMapTools.prototype.getLocation = function(callback) {
|
let self = this;
|
let geoc = this.geoc;
|
this.getPoint(function(r) {
|
geoc.getLocation(r.point, function(rs){
|
if(typeof callback == 'function') {
|
callback(rs);
|
}
|
});
|
});
|
};
|
|
export default BMapTools;
|