首页 > 微信 > 详细

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

时间:2018-03-01 18:24:57      阅读:706      评论:0      收藏:0      [点我收藏+]

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

 

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

原文:https://www.cnblogs.com/e0yu/p/8489700.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!