Map Location
WdLocation
Notes
This component calls the Tencent Maps service and consumes relevant API quotas. You can visit the Tencent Maps Open Platform to view key consumption. For details, refer to the key Quota Description.
Applicable Scenarios
Point selection and positioning in forms
Basic Capabilities
Binding the "Geographic Location" Field
After the form container is bound to a data model, the "Geographic Location" field in the model will be automatically rendered as a map location component, enabling point selection and positioning.
Configuration Guide
The map location component requires map API configuration to be used. Click on Map API and select Tencent Maps API. If no API exists, create a new Tencent Maps API first. For details, refer to Tencent Maps API.
For mini program usage, configure according to the following steps
- WeChat Mini Program applications call the WeChat official wx.getLocation interface for positioning. They must comply with the category restrictions imposed by Mini Programs (specific categories are described in the wx.getLocation documentation click to view). On the WeChat Official Accounts Platform, navigate to "Development" - "Development Management" - "Interface Settings" module, and self-enable the permission for the "Obtain current geographic location and speed" interface.
- Due to Mini Program restrictions: To ensure developers can properly use interfaces such as obtaining approximate geographic location and for subsequent optimization of the code review process, starting from July 14, 2022, developers need to configure in app.json in advance when using location-related interfaces. WeChat Documentation Please open the low-code editor's commom/mp_config file and configure the following properties in appJson
appJson: {
// Mini Program interface permission related settings, optional
permission: {
'scope.userLocation': {
'desc': 'Your location information will be used to demonstrate the effects of the Mini Program location interface',
},
},
requiredPrivateInfos: [ "getLocation" ]
}Mini Program submission review error description (Open the console to view error messages)
- Error message: Failed to request WeChat API data; 61040; The code contains ext.json without configuring the privacy interface getLocation (temporarily set requiredPrivacyType_use to true) before resubmitting for review. Please refer to the second step in the Mini Program configuration above to configure the appJson file
- Error message: Failed to request WeChat API data; 61040; The privacy interface getLocation configured in ext.json has no permission. Please apply for the permission before resubmitting for review. Refer to the first step in the Mini Program configuration above to apply for the wx.getLocation interface permission.
Browser Location Failure Description:
1) Browser not Support html5 geolocation: The browser does not support native location interfaces, such as lower versions of IE browsers.
2) Geolocation permission denied: The user has disabled location permissions. They need to enable location permissions for both the device and browser, and click the "Allow location access" option in the browser popup.
3) Geolocation permission denied: Browsers block location requests from non-secure origins. For example, Chrome and IOS10 have successively implemented this restriction. In such cases, you need to upgrade the site to HTTPS. Note that Chrome does not block location under HTTP protocol for domains like localhost.
4) Geolocation permission denied: Access to geolocation was blocked over secure connection with mixed content, meaning http resources are referenced within an Https page.
5) Get geolocation time out: Browser location timeout, including native timeouts. You can increase the timeout setting appropriately to reduce this occurrence. Additionally, the location interface of certain browsers (such as google Chrome) is a black hole, where location requests receive no response and eventually time out, resulting in failure.
6) Get geolocation failed: Location failure occurs because Chrome, Firefox, and some shell browsers access location services that are located abroad, which are subject to significant restrictions, resulting in a high failure rate.
Quota Limitation Description: After the map location component is configured with Tencent Maps API, the quota limitations of Tencent Maps API will affect the usage of the map location component. For details, refer to: Quota Limitation Description
The main services used within the component include:
Service Name Service Path Nearby Recommendations /ws/place/v1/explore Place Search /ws/place/v1/search Keyword Input Suggestion /ws/place/v1/suggestion Geocoding /ws/geocoder/v1/?address=*
Extended Scenarios
Positioning Adjustment Range Configuration
The component provides a "Positioning Adjustment Range" attribute to constrain the user's point selection range, allowing selections only within a specified distance from the current actual location point.
Other Scenario Practices
Refer to the Form Scenario Practice Guide to learn about various supported scenarios and implementation solutions for forms.
Example
Interactive Preview
Component Input State
Style API Example
#wd-page-root .wd-pc-location-root .wd-location__label {
color: cyan;
background-color: black;
display: flex;
justify-content: center;
}
#wd-page-root .wd-h5-location-root .wd-location-location {
border-color: cyan;
color: cyan;
background-color: black;
border-width: 2px;
border-radius: 6px;
}
Properties
组件接收的外部传入的属性
属性名 | 属性标识 | 类型 | 说明 |
---|
显示标题 | labelVisible | boolean | 默认值:true |
标题对齐 | labelAlign | string | 表单场景下默认会跟随表单容器的标题对齐配置 |
标题换行 | labelWrap | boolean | 如果标题内容过长关闭时只显示一行、溢出省略;开启时换行展示。表单场景下默认会跟随表单容器的标题换行配置 |
标题位置 | layout | string | 设置标题在表单组件的展示位置,表单场景下默认会跟随表单容器的标题的位置配置 |
标题宽度 | labelWidth | string | 表单场景下默认会跟随表单容器的标题宽度配置 |
标题提示 | labelTips | string | 配置标题的工具提示内容 |
显示清空按钮 | clearable | boolean | 开启后提供快捷清空按钮 默认值:true |
下方提示 | extra | string | 配置后提示内容常显在输入框下方 |
显示经纬度 | showLngLat | boolean | 显示所选位置的经纬度 |
显示地图 | showMap | boolean | 显示所选位置的地图 |
移动端显示下划线 | borderedH5 | boolean | 关闭后移动端不显示底部下划线 默认值:true |
定位调整范围 | locationRange | string | 0 |
自定义范围米 | customRange | number | 0 |
允许缩放 | zoom | boolean | 允许缩放地图 默认值:true |
允许拖动 | drag | boolean | 允许拖动地图 示例:true |
状态 | status | string | 示例:"edit" |
必填 | required | boolean | |
必填标识 | requiredFlag | boolean | 启用后,组件若要求必填,则会显示必填星号标记 默认值:true |
必填校验提示 | requiredMsg | string | 示例:"该项为必填项" |
绑定字段 | name | string | 表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。 |
标题内容 | label | string | 示例:"地图" |
地图APIs | dataSource | object | 关联腾讯地图的APIs,小程序会调用微信官方接口实现定位,请确保已通过相关接口申请,详细说明可查看该组件说明文档 |
默认位置 | locationType | number | 地理位置的默认值 示例:1 |
默认值 | value | object | 示例:null |
占位文字 | placeholder | string | 示例:"选择地理位置" |
Events
组件暴露的事件,可以监听组件的事件来触发一些外部的动作
事件名 | 事件code | 事件出参 event.detail | 适用情况 | 说明 |
---|
值改变 | change | object
| 兼容三端 | 用户修改组件值时触发 |
地图组件错误事件 | error | object
| 移动端,PC端 | 地图加载失败,或地图组件使用异常时触发 |
Property API
通过属性 API,可以获取组件内部的状态和属性值,可以通过$w.componentId.propertyName
来访问组件内部的值,如 $w.input1.value
,详请请参考 属性 API
只读属性名 | 属性标识 | 类型 | 说明 |
---|
绑定字段 | name | string | 表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。 |
标题内容 | label | string | |
默认值 | value | object | |
必填 | required | boolean | |
是否展示 | visible | boolean | 组件是否展示 |
是否禁用 | disabled | boolean | 组件是否禁用 |
是否只读 | readOnly | boolean | 组件是否只读 |
Method API
通过方法 API,可以通过程序触发组件内部的方法,比如提交表单,显示弹窗等, 可以通过$w.componentId.methodName
来调用组件方法,如 $w.form1.submit()
方法名 | 方法标识 | 参数 | 方法说明 |
---|
设置值 | setValue | object
| 通过 $w.id1.setValue({address:"深圳站",geopoint:{coordinates:[114.117209,22.53168]}}) 设置组件值 |
设置显隐 | setVisible | boolean 显示 | 通过 $w.id1.setVisible(false) 设置组件为隐藏 |
设置禁用 | setDisabled | boolean 禁用 | 通过 $w.id1.setDisabled(true) 设置组件为禁用 |
清空值 | clearValue | 通过 $w.id1.clearValue() 清空组件值 | |
设置只读 | setReadOnly | boolean 只读 | 通过 $w.id1.setReadOnly(true) 设置组件为只读 |
触发校验 | handleValidate | 通过 $w.id1.handleValidate() 校验组件值 | |
清除校验 | clearValidate | 通过 $w.id1.clearValidate() 清除组件校验 |
Style API
通过样式 API,可以覆盖组件中内部元素的样式来实现自定义,例如在低代码编辑器中中通过 #wd-page-root .wd-btn
即可为所有的按钮组件编写样式,通过 :scope
可以控制单个组件样式, 详细说明请参考样式 API
名称 | 类名 | 说明和示例 |
---|
根元素 | .wd-location-root | 组件最外层元素
|
H5 端根元素 | .wd-h5-location-root | 可设定 H5 端的根元素样式
|
PC 端根元素 | .wd-pc-location-root | 可设定 PC 端的根元素样式
|
小程序端根元素 | .wd-mp-location-root | 可设定小程序端的根元素样式
|
组件标题样式 | .wd-location-root .wd-form-item-wrap__label | 组件标题元素
|
表单控件根节点样式 | .wd-location-root .wd-form-item-wrap__control | 设置表单控件根元素样式
|
编辑态-位置信息样式 | .wd-location-root .wd-location__info | 编辑态-位置信息样式
|
编辑态-占位文字样式 | .wd-location-root .form-location-con__text | 编辑态-占位文字样式
|
编辑态-校验信息 | .wd-location-root .wd-g-text-error | 设置组件校验信息样式
|
提示文字 | .wd-location-root .wd-form-item__help-text | 设置组件提示文字样式
|
禁用态-位置信息样式 | .wd-location-root .is-disabled .wd-location__info | 禁用态-位置信息样式
|
只读态-表单值样式 | .wd-location-root .wd-form-item__readonly-value | 设置组件只读状态
|
Version Changes
- Property changes
- Style changes
- widget api changes