获取定位

获取用户定位

1.navigator.geolocation

//翻*墙才好用

if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
console.log('纬度:'+position.coords.latitude+'经度:'+position.coords.longitude);
},function(err){
console.log(err.code,err.message);
})
}else{
console.log('您当前使用的浏览器不支持Geolocaton服务');
}
2.微信接口
wx.getLocation({
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
lat = res.latitude; // 纬度,浮点数,范围为90 ~ -90
lng = res.longitude; // 经度,浮点数,范围为180 ~ -180。
}
});
原文地址:https://www.cnblogs.com/llllpzyy/p/7910915.html