<template>
  <map
    :latitude="latitude"
    :longitude="longitude"
    :markers="markers"
    :polygons="polygons"
    :polyline="polyline"
    id="map"
    ref="map"
    show-location="true"
    include-points="true"
    style="width: 100%; height: 1000rpx;"
  />
</template>

<script>
export default {
  props: {
    markers: { type: Array, default: null },
    polyline: { type: Array, default: null },
    polygons: { type: Array, default: null },
  },
  data() {
    return {
      latitude: 37.87059,
      longitude: 112.55067,
    };
  },

  onLoad() {
    this.getLocation();
  },

  methods: {
    // 获取当前的地址位置
    // 注意用国测局的数据 map只支持gcj02
    getLocation() {
      uni.getLocation({
        type: 'gcj02',
        success: res => {
          this.longitude = res.longitude;
          this.latitude = res.latitude;
          console.log('当前位置的经度：' + res.longitude);
          console.log('当前位置的纬度：' + res.latitude);
        },
      });
    },
  },
};
</script>
