1.如果是在微信小程序中使用导航,需要使用腾讯地图线路规划插件,
getLocation() {
let that = this
// 获取用户是否开启 授权获取当前的地理位置、速度的权限。
uni.getSetting({
success(res) {
console.log(res)
// 如果没有授权
if (!res.authSetting['scope.userLocation']) {
// 则拉起授权窗口
uni.authorize({
scope: 'scope.userLocation',
success() {
//点击允许后--就一直会进入成功授权的回调 就可以使用获取的方法了
uni.getLocation({
type: 'gcj02',
success: res => {
// 获取到坐标后存起来
that.latitude = res.latitude
that.longitude = res.longitude
console.log(res, 0)
// 使用地图实例中的方法,让标记和我的位置都在可视区域里显示