微信小程序 --- 获取当前坐标

获取位置:get.location 

type:wgs84(是全球定位系统,获取的坐标,gcj02是国家测绘局给出的坐标)

btnclick:function(){
    wx.getLocation({
        type:‘wgs84‘,// 默认wgs84
        success:function(res){},
        fail:function(res){},
        complete:function(){}
    });
}

 

查看位置:有两个

第一个:wx.chooseLocation:可以打开地图进行选择,之后返回给 complete 

btnclick:function(){
    wx.getLocation({
        success:function(res){
            var latitude = res.latitude;
            var longitude = res.longitude;
            wx.chooseLocation({
                latitude = latitude,
                longitude = longitude,
                success:function(res){
                    console.log(res);
                },
                fail:function(){},
                complete:function(){}
            });
        }
    });
}

第二个:wx.openLocation:使用微信内置地图查看位置

btnclick:function(){
    wx.getLocation({
        success:function(res){
            var latitude = res.latitude;
            var longitude = res.longitude;
            wx.openLocation({
                latitude = latitude,
                longitude = longitude,
                scale:28
            });
        }
    });
}

 

微信小程序 --- 获取当前坐标

上一篇:数据结构与算法(C#)入门 --- 线性表


下一篇:彻底理解容器类(2)------- AbstractCollection深入了解