cv-geo-local 带地图选择的地址输入框 ¶
简要 ¶
带地图选择的地址输入框,一般和表单配合使用,默认为实心白色背景。
示例 ¶
vue
<template>
<view class="content">
<view class="components-title">
<view class="components-title-t">cv-geo-local</view>
<view class="components-title-d">可在地图中选择地址</view>
</view>
<view class="components-info">
<view class="components-info-list" v-if="location_data">
<view class="components-info-list-title">@onLocation:</view>
<view class="components-info-list-item">
<!-- #ifdef MP-WEIXIN -->
<view v-for="(item, key) in location_data" :key="key">
<text>″{{ key }}″:</text>
<text>{{ ' ″' + item + '″' }}</text>
</view>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<text>{{ location_data }}</text>
<!-- #endif -->
</view>
</view>
<view class="components-info-list-tip" v-else>
<view><text>未选择</text></view>
<view><text>点击输入框右侧搜索按钮选择地址</text></view>
</view>
</view>
<cv-form-base ref="refFormBase" :rules="formRules" :model="formData" style="padding: 0 10px" labelWidth="84">
<cv-form-item label="详细地址1">
<cv-geo-local v-model="formData.address1" @location="onLocation" />
</cv-form-item>
<cv-form-item label="详细地址2" labelPosition="top">
<cv-geo-local v-model="formData.address2" @location="onLocation" isShowMap />
<template v-slot:tip>有地图</template>
</cv-form-item>
<cv-form-item label="详细地址3" labelPosition="top">
<cv-geo-local v-model="formData.address3" @location="onLocation" :location="location" isShowMap />
<template v-slot:tip>有地图和默认地理位置</template>
</cv-form-item>
</cv-form-base>
<view style="height: 50px"></view>
</view>
</template>
<script>
export default {
data() {
return {
formRules: {},
formData: {
address1: '',
address2: '',
address3: ''
},
location: {},
location_data: null
};
},
onLoad() {
setTimeout(() => {
this.formData = {
address1: '福建省福州市仓山区浦上大道198号123132',
address3: '福建省福州市仓山区浦上大道198号'
};
this.location = {
latitude: '26.040905',
longitude: '119.279148'
};
}, 1000);
},
methods: {
onLocation(e) {
this.location_data = e;
}
}
};
</script>
<style>
.components-info {
background-color: #ffffff;
padding: 10px;
}
.components-info-title {
text-align: center;
line-height: 40px;
font-size: 16px;
}
.components-info-list,
.components-info-list-tip {
margin: 20px 0;
}
.components-info-list-tip {
text-align: center;
font-size: 12px;
color: #99999999;
}
.components-info-list-title {
font-size: 12px;
color: #999999;
}
.components-info-list-item {
font-size: 12px;
color: #666666;
padding-left: 40px;
}
</style>
属性 ¶
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
v-model | String | - | 数据双向绑定 |
placeholder | String | - | 占位符 |
disabled | Boolen | false | 是否禁止 |
maxlength | Number | -1 | 输入长度限制 |
clearable | Boolean | false | 是否显示一键清空按钮 |
isShowMap | Boolean | false | 是否显示地图预览 |
location | Object | {} | 初始化地图中心点位置 |
scale | Number | 14 | 地图缩放等级 |
- [
location
]结构
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
latitude | String | - | 纬度 |
longitude | String | - | 经度 |
事件 ¶
事件名 | 说明 | 返回值 |
---|---|---|
@location | 监听 | 地址信息 |
- [
@location
] 返回参数
属性名 | 说明 |
---|---|
name | 位置名称 |
address | 详细地址 |
latitude | 纬度,浮点数,范围为-90~90,负数表示南纬,使用 gcj02 国测局坐标系。 |
longitude | 经度,浮点数,范围为-180~180,负数表示西经,使用 gcj02 国测局坐标系。 |