mapContext=uni.createMapContext('map', this);
mapContext.moveToLocation({
longitude:lon,
latitude:lat,
success:res=>{
console.log(res)
},
fail:err=>{
console.log(err)
}
})
![大苏](http://img-cdn-tc.dcloud.net.cn/uploads/avatar/000/13/21/12_avatar_mid.jpg?v=1658476299)
- 发布:2020-06-17 13:47
- 更新:2021-05-31 02:17
- 阅读:3435
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: Alpha
HBuilderX版本号: 2.7.13
手机系统: iOS
手机系统版本号: iOS 13.4
手机厂商: 苹果
手机机型: 6splus
页面类型: nvue
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
moveToLocation指定经纬度后移动到当前定位的位置
moveToLocation指定经纬度后移动到当前定位的位置
预期结果:
moveToLocation指定经纬度后移动到指定的位置
moveToLocation指定经纬度后移动到指定的位置
实际结果:
moveToLocation指定经纬度后移动到当前定位的位置
moveToLocation指定经纬度后移动到当前定位的位置
bug描述:
moveToLocation指定经纬度,却只能移动到当前定位的位置,在android6.0的手机和iphone6splus手机都是这样
![DCloud_uni-ad_HDX](http://img-cdn-tc.dcloud.net.cn/uploads/avatar/001/01/98/35_avatar_mid.jpg?v=0)
更新HBuilderX 2.8.2+
<template>
<view>
<map id="test_map" ref="map1" style="width: 750rpx; height: 300px;" :show-location="true" :longitude="map.longitude"
:latitude="map.latitude">
</map>
<button @click="dingwei">定位到"北京西站"</button>
<button @click="dingwei2">ref 定位到"北京西站"</button>
</view>
</template>
<script>
export default {
data() {
return {
map: {
longitude: '', //经度
latitude: '', //纬度
}
}
},
onLoad() {
let _this = this;
uni.getLocation({
type: 'gcj02',
success: function(res) {
_this.map.longitude = res.longitude;
_this.map.latitude = res.latitude;
}
});
},
onReady() {
this.mapContext = uni.createMapContext('test_map', this);
},
methods: {
dingwei() {
this.mapContext.moveToLocation({
//该固定坐标为高德地图拾取,位置:北京西站
latitude: 39.894589,
longitude: 116.32125,
success: function(res) {
console.log("此处无回调!!!本条信息未在控制台打印");
console.log(res);
}
});
},
dingwei2() {
this.$refs.map1.moveToLocation({
//该固定坐标为高德地图拾取,位置:北京西站
latitude: 39.894589,
longitude: 116.32125
},
function(res) {
console.log("此处无回调!!!本条信息未在控制台打印");
console.log(res);
}
);
}
}
}
</script>
<style>
</style>
6***@qq.com
我的HbuilderX是2.7.14版本,已经没有V3编译的勾选框了,应该是默认的V3编译。moveToLocation移动到指定经纬度在android端是有效的,在ios 端无效,只会移动到当前的定位
2020-06-30 08:30
jxtian
回复 694234172@qq.com:ios刚验证了一下没有问题,你可以提供一下你的代码吗?
2020-06-30 11:51
6***@qq.com
<button type="default" @click="moveToLocation">移动到指定位置</button>
</view>
</template>
<script>
export default {
data() {
return {
longitude: null,
latitude: null,
showLocation: true,
mapObj: null
}
},
mounted() {
this.getLocaltion()
},
methods: {
getLocaltion() {
console.log("getLocation---start")
uni.getLocation({
type: 'gcj02',
success: (res) => {
console.log(res)
this.longitude = res.longitude;
this.latitude = res.latitude;
},
fail(e) {
console.log(e)
}
});
},
moveToLocation() {
this.$refs.map1.moveToLocation({
longitude: 106.6221,
latitude: 26.593
})
}
}
}
</script>
<style>
.container {
font-size: 14px;
line-height: 24px;
}
</style>
2020-06-30 14:25
6***@qq.com
回复 jxtian: 刚刚又测了一下,用vue页面android 和ios 都可以的。但是我用的是nvue,所以ios不生效。
但是用vue页面初始化页面的时候地图中心没有那个当前定位角标啊~难过
2020-06-30 14:30
6***@qq.com
回复 jxtian: 你这边验证过后有这个情况么?
2020-07-06 09:36