获取经纬度

// 异步
created () {
        let lng, lat;
        if (navigator.geolocation && navigator.geolocation.getCurrentPosition) {
            console.log('navigator 1', navigator);

            navigator.geolocation.getCurrentPosition((position) => {
                lng = position.coords.longitude;
                lat = position.coords.latitude;
                console.log('geo getCurrentPosition', lng, lat);

                this.doGetTypeList(lng, lat);
            }, (error) => {
                console.log(error, '===error');
                this.doGetTypeList(lng, lat);
            });
        } else {
            this.doGetTypeList(lng, lat);
        }
        console.log('navigator', navigator);
        console.log('geo', lng, lat);
    },

你可能感兴趣的:(获取经纬度)