uniapp中map地图定位的使用

本文详细介绍了如何在uniapp中实现类似外卖系统的地图定位功能,包括设置地图中心、marker标记、polyline路径和circles圆圈,以及自定义控件和label。

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

uniapp中map地图定位的使用

有时h5为了实现类似外卖系统的地图定位,如下图所示

在这里插入图片描述
代码如下

<template>
  <view>
    <view class="page-body">
      <view class="page-section page-section-gap">
        <map
          style="width: 100vw; height: 100vh"
          :latitude="latitude"
          :longitude="longitude"
          :markers="covers"
          :polyline='polyline'
          :circles='circles'
          :controls='controls'
        >
        </map>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      id: 0, // 使用 marker点击事件 需要填写id
      title: "map",
      latitude: 34.75975, //设置地图中心的经纬度
      longitude: 113.664839, //设置地图中心的经纬度
      covers: [
        {
          callout: {
            borderRadius: 10,
            padding: 10,
            bgColor: "#CDDFF3",
            color: "#f00",
            fontSize: 10,
            content: `北京市`,
          }, //设置点击后显示的文字及其样式
          label: {
            content: "商家", //文本内容
            color: "black", //文本颜色
            bgColor: "#fff", //文本背景色
            fontSize: 10, //文本字体大小
            x: -20, //label的坐标,原点是 marker 对应的经纬度
            y: 30, //label的坐标,原点是 marker 对应的经纬度
            borderWidth: 12, //边框宽度
            borderColor: "pink", //边框颜色
            borderRadius: 20, //边框圆角
            bgColor: "black", //背景色
            padding: 5, //文本边缘留白
            textAlign: "right", //文本对齐方式。
          }, //设置地点旁边的文字及样式
          latitude: 34.75967,
          longitude: 113.664847,
          iconPath: "../../static/img/tabsListTemplate/fire.png",
          width: 20, //控件宽
          height: 20, //控件高
        },
        {
          latitude: 34.75874,
          longitude: 113.664838,
          iconPath: "../../static/img/tabsListTemplate/fire.png",
        },
      ],
      circles: [
        {
          //在地图上显示圆
          latitude: 34.75874,
          longitude: 113.664838,
          fillColor: "#999999", //填充颜色
          color: "#0016ca", //描边的颜色
          radius: 20, //半径
          strokeWidth: 1, //描边的宽度
        },
      ],
      polyline: [
        {
          //指定一系列坐标点,从数组第一项连线至最后一项
          points: [
            { latitude: 34.75874, longitude: 113.664838 },
            { latitude: 34.75967, longitude: 113.664847 },
          ],
          color: "#0000AA", //线的颜色
          width: 2, //线的宽度
          dottedLine: true, //是否虚线
          arrowLine: true, //带箭头的线 开发者工具暂不支持该属性
        },
      ],
      controls: [
        {
          //在地图上显示控件,控件不随着地图移动
          id: 1, //控件id
          iconPath: "../../static/img/tabsListTemplate/fire.png",
          position: {
            //控件在地图的位置
            left: 15,
            top: 15,
            width: 50,
            height: 50,
          },
        },
      ],
    };
  },

  mounted() {},

  methods: {},
};
</script>
<style lang='less' scoped>
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值