longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;