Skip to main content

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

  1. 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.

  2. For mini program usage, configure according to the following steps

    1. 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.

    img

    1. 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" ]
    }

    img

  3. Mini Program submission review error description (Open the console to view error messages)

    1. 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
    2. 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.
  4. 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.

  5. 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 NameService 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

组件接收的外部传入的属性

属性名
属性标识
类型
说明
显示标题labelVisibleboolean

默认值:true

标题对齐labelAlignstring

表单场景下默认会跟随表单容器的标题对齐配置

标题换行labelWrapboolean

如果标题内容过长关闭时只显示一行、溢出省略;开启时换行展示。表单场景下默认会跟随表单容器的标题换行配置

标题位置layoutstring

设置标题在表单组件的展示位置,表单场景下默认会跟随表单容器的标题的位置配置

标题宽度labelWidthstring

您可以输入数值 + px、%等单位,示例:200px

表单场景下默认会跟随表单容器的标题宽度配置

标题提示labelTipsstring

PC/H5端生效

配置标题的工具提示内容

显示清空按钮clearableboolean

开启后提供快捷清空按钮

默认值:true

下方提示extrastring

配置后提示内容常显在输入框下方

显示经纬度showLngLatboolean

显示所选位置的经纬度

显示地图showMapboolean

显示所选位置的地图

移动端显示下划线borderedH5boolean

关闭后移动端不显示底部下划线

默认值:true

定位调整范围locationRangestring0
自定义范围米customRangenumber0
允许缩放zoomboolean

允许缩放地图

默认值:true

允许拖动dragboolean

允许拖动地图

示例:true

状态statusstring

示例:"edit"

必填requiredboolean
必填标识requiredFlagboolean

启用后,组件若要求必填,则会显示必填星号标记

默认值:true

必填校验提示requiredMsgstring

示例:"该项为必填项"

绑定字段namestring

表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。

标题内容labelstring

示例:"地图"

地图APIsdataSourceobject

如需小程序端使用,请务必参考 配置指引 完成微信接口权限申请,并调整appJson内容

关联腾讯地图的APIs,小程序会调用微信官方接口实现定位,请确保已通过相关接口申请,详细说明可查看该组件说明文档

默认位置locationTypenumber

地理位置的默认值

示例:1

默认值valueobject

纬度,范围为-90~90;经度,范围为-180~180,位置经纬度可前往腾讯位置服务获取 去获取

示例:null

占位文字placeholderstring

示例:"选择地理位置"

Events

组件暴露的事件,可以监听组件的事件来触发一些外部的动作

事件名
事件code
事件出参 event.detail
适用情况
说明
值改变changeobject
  • value: object
    • address: string

      地点名称

    • geopoint: object

      经纬度

      • type: string 默认值:Point
      • coordinates: array
兼容三端

用户修改组件值时触发

地图组件错误事件errorobject
  • error: object 错误信息

    组件内部抛出的错误信息

    • requestid: string请求 id

      如果是接口相关错误会提供请求 id

    • message: string错误提示信息
    • code: string错误码
    • original: 原始错误
移动端,PC端

地图加载失败,或地图组件使用异常时触发

Property API

通过属性 API,可以获取组件内部的状态和属性值,可以通过$w.componentId.propertyName 来访问组件内部的值,如 $w.input1.value ,详请请参考 属性 API

只读属性名
属性标识
类型
说明
绑定字段namestring

表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。

标题内容labelstring
默认值valueobject
必填requiredboolean
是否展示visibleboolean

组件是否展示

是否禁用disabledboolean

组件是否禁用

是否只读readOnlyboolean

组件是否只读

Method API

通过方法 API,可以通过程序触发组件内部的方法,比如提交表单,显示弹窗等, 可以通过$w.componentId.methodName来调用组件方法,如 $w.form1.submit()

方法名
方法标识
参数
方法说明
设置值setValueobject
  • value: object
    • address: string

      地点名称

    • geopoint: object

      经纬度

      • type: string 默认值:Point
      • coordinates: array

通过 $w.id1.setValue({address:"深圳站",geopoint:{coordinates:[114.117209,22.53168]}}) 设置组件值

设置显隐setVisibleboolean显示

通过 $w.id1.setVisible(false) 设置组件为隐藏

设置禁用setDisabledboolean禁用

通过 $w.id1.setDisabled(true) 设置组件为禁用

清空值clearValue

通过 $w.id1.clearValue() 清空组件值

设置只读setReadOnlyboolean只读

通过 $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组件最外层元素
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope.wd-location-root {
  /* 在这里编写CSS 样式 */
}
H5 端根元素.wd-h5-location-root可设定 H5 端的根元素样式
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope.wd-h5-location-root {
  /* 在这里编写CSS 样式 */
}
PC 端根元素.wd-pc-location-root可设定 PC 端的根元素样式
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope.wd-pc-location-root {
  /* 在这里编写CSS 样式 */
}
小程序端根元素.wd-mp-location-root可设定小程序端的根元素样式
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope.wd-mp-location-root {
  /* 在这里编写CSS 样式 */
}
组件标题样式.wd-location-root .wd-form-item-wrap__label组件标题元素

:scope .wd-form-item-wrap__label {
  font-size: 20px;
  color: gray;
  padding: 0;
  display: flex;
  align-items: center;
}
表单控件根节点样式.wd-location-root .wd-form-item-wrap__control设置表单控件根元素样式

:scope .wd-form-item-wrap__control {
  font-size: 20px;
  color: gray;
  padding: 0;
  display: flex;
  align-items: center;
}
编辑态-位置信息样式.wd-location-root .wd-location__info编辑态-位置信息样式

          :scope .wd-location__info {
font-size: 20px;
color: gray;
          }
          
编辑态-占位文字样式.wd-location-root .form-location-con__text编辑态-占位文字样式

          :scope .form-location-con__text {
color: lightgray;
          }
          
编辑态-校验信息.wd-location-root .wd-g-text-error设置组件校验信息样式

:scope .wd-g-text-error {
    font-size: 20px;
    color: gray;
  }
提示文字.wd-location-root .wd-form-item__help-text设置组件提示文字样式

:scope .wd-form-item__help-text {
    font-size: 20px;
    color: gray;
  }
禁用态-位置信息样式.wd-location-root .is-disabled .wd-location__info禁用态-位置信息样式

          :scope .is-disabled .wd-location__info {
font-size: 20px;
color: gray;
          }
          
只读态-表单值样式.wd-location-root .wd-form-item__readonly-value设置组件只读状态

:scope .wd-form-item__readonly-value {
    font-size: 20px;
    color: gray;
  }

了解样式 API

Version Changes

  • Property changes
  • Style changes
  • widget api changes