uni-app-地图中心设置图标-获取坐标

1. 在地图中加入一个自己需要的图标,一般使用图片,定位方便


    

2. 设置样式

注意,最好把定位点放在地图中心,方便获取坐标

.mapCenter {
    width: 60rpx;
    height: 60rpx;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
}

3. 调用getCenterLocation方法

const add = res => {
    console.log('当前坐标==>',res.latitude,res.longitude)
    // 向点位数组中添加一个点位
    this.markers.push({
        id:this.markers.length,
        latitude: res.latitude,
        longitude: res.longitude,
        iconPath: '../../../static/location.png',
    })
}
uni.createMapContext('map', this).getCenterLocation({
    success:add
})
​

4. 最终效果

pc端啥也看不见,真机测试有数据

uni-app-地图中心设置图标-获取坐标_第1张图片

 

你可能感兴趣的:(Web前端,javascript,vue.js,uni-app)