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

本文介绍了如何在uni-app中设置地图中心的图标,并通过getCenterLocation方法获取坐标,强调真机测试的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

<map
    style="width: 100%; height: 100%;"
    id="map"
    :latitude="latitude"
    :longitude="longitude"
    :markers="markers"
    :scale='scale'
    :circles="circles"
    @markertap='toChangePoint'
    show-location='true'
>
    <image class="mapCenter" src="@/static/cross.png"></image>
</map>

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:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值