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

获取位置: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
            });
        }
    });
}

 

posted @ 2018-03-01 17:47  帅到要去报警  阅读(8663)  评论(1编辑  收藏  举报