uniapp-Map地图之打标点与使用

在uniapp开发中,会涉及到定位方面的需求,比如查询用户附近的门店,在餐饮与外卖应用中广泛存在,今天就来记录一下uniapp中map组件的使用与打标点

1.初始化map

    <map
      id="map"
      :latitude="latitude"
      :longitude="longitude"
      :scale="13"
      :markers="markers"
      :show-location="true"
      style="width: 100%; height: 400rpx"
      >
    </map>

latitude/longitude为用户当前所在定位,用来标记用户当前地理位置,如图

scale为地图缩放比例,值越大地图越详细

markers为标点集合

具体说明见官方文档map | uni-app-x

2.打标点

注意:id只能唯一,若重复会出现标点不全或只显示一个等问题

 iconPath为自定义标点图标,只能是相对路径/static这种模式,不能是绝对路径../static

      // 将门店数据转换为 markers 数组
        this.markers = rel.data.map((store) => ({
          id: store.storeCode, // 确保 id 是数字
          latitude: parseFloat(store.lat), // 确保 latitude 是数字
          longitude: parseFloat(store.lng), // 确保 longitude 是数字
          title: store.name,
          iconPath: "/static/orderingMeals/location.png",
          width: 30,
          height: 30,
        }));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值