获取地理位置定位信息-app端

获取地理位置定位信息-app端

getLoad() { 
    let site = { }
    let onSuccess = (position) => { 
        site.code = 0
        //获取经纬度
        site.position = [position.coords.longitude, position.coords.latitude]

        let map = new BMap.Map("allmap");
        let point = new BMap.Point(site.position[0],site.position[1]);
        let gc = new BMap.Geocoder();
        let that = this 
        gc.getLocation(point, function(rs) { 
            // alert(rs.sematic_description);
            let addComp = rs.addressComponents;
            let mapAddress = addComp.province+addComp.city + addComp.district
            + addComp.street + addComp.streetNumber;
            //获得地理位置名称
            alert(mapAddress)
        }); 
    }
    let onError = (error) => { 
        site.code = error.code
        site.position = error.message
    }
    navigator.geolocation.getCurrentPosition(onSuccess, onError, { 
        maximumAge: 3000,
        timeout: 5000,
        enableHighAccuracy: true
    })
},
    原文作者:wild_guiqulaixi
    原文地址: https://blog.csdn.net/Allanwhy/article/details/96429987
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞