Skip to content

Location Picker 地图选点

用于表单选取地图点位。

全局配置

在全局配置组件属性。

LocationPicker组件属性配置
ts
app.provide(LOCATION_PICKER_KEY, {
  type: 'wgs84',
  layersControl: true,
  loadOptions: {
    // 必填,如果已经在高德地图组件中配置了key,则无需重复配置
    key: '替换为你申请的 key',
  },
  mapOptions: {
    center: [115.857972, 28.682976],
  },
  // others props...
});

基础用法

v-model参数

v-model支持单独绑定经度、纬度或地址。

指定坐标系

通过type属性可以指定坐标系,默认为gcj02,推荐在全局配置中统一指定项目所使用的坐标系。

属性透传

Location Picker基于LivAMap封装,所以你可以传入LivAMap的所有属性。

属性

属性名说明类型默认值
model-value / v-model选中位置的经纬度数组number[]
longitude / v-model:longitude选中位置的经度number
latitude / v-model:latitude选中位置的纬度number
address / v-model:address2.1.0选中位置的地址string
type经纬度坐标系enumgcj02

事件

事件名说明类型默认值
change点击地图位置改变后的回调Function
confirm点击确认按钮后的回调Function
类型声明
ts
import type { AMapProps } from '../../a-map';
import LocationPicker from './location-picker.vue';

/**
 * 位置选择器组件属性
 */
export interface LocationPickerProps extends AMapProps {
  /**
   * 坐标系类型
   * @defaultValue 'gcj02'
   */
  type?: 'gcj02' | 'wgs84';
}

/**
 * 位置选择器组件事件
 */
export type LocationPickerEmits = {
  change: [location: [number | null, number | null]];
  confirm: [location: [number, number]];
};

/**
 * 位置选择器组件实例
 */
export type LocationPickerInstance = InstanceType<typeof LocationPicker>;