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

External properties received by the component

Property Name
Property Identifier
Type
Description
显示标题labelVisibleboolean

Default value: true

标题对齐labelAlignstring

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

标题换行labelWrapboolean

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

标题位置layoutstring

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

标题宽度labelWidthstring

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

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

标题提示labelTipsstring

PC/H5端生效

配置标题的工具提示内容

显示清空按钮clearableboolean

开启后提供快捷清空按钮

Default value: true

下方提示extrastring

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

显示经纬度showLngLatboolean

显示所选位置的经纬度

显示地图showMapboolean

显示所选位置的地图

移动端显示下划线borderedH5boolean

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

Default value: true

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

允许缩放地图

Default value: true

允许拖动dragboolean

允许拖动地图

Example: true

状态statusstring

Example: "edit"

必填requiredboolean
必填标识requiredFlagboolean

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

Default value: true

必填校验提示requiredMsgstring

Example: "该项为必填项"

绑定字段namestring

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

标题内容labelstring

Example: "地图"

地图APIsdataSourceobject

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

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

默认位置locationTypenumber

地理位置的默认值

Example: 1

默认值valueobject

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

Example: null

占位文字placeholderstring

Example: "选择地理位置"

Events

Events exposed by the component. You can listen to component events to trigger external actions

Event Name
Event Code
Event Output Parameters event.detail
Applicable Scenarios
Description
值改变changeobject
  • value: object
    • address: string

      地点名称

    • geopoint: object

      经纬度

      • type: string Default value: Point
      • coordinates: array
Compatible with all platforms

用户修改组件值时触发

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

    组件内部抛出的错误信息

    • requestid: string请求 id

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

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

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

Property API

Through the Property API, you can access the internal state and property values of components. You can access internal values using$w.componentId.propertyName, such as $w.input1.value. For details, please refer to Property API

Read-only Property Name
Property Identifier
Type
Description
绑定字段namestring

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

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

组件是否展示

是否禁用disabledboolean

组件是否禁用

是否只读readOnlyboolean

组件是否只读

Method API

Through the Method API, you can programmatically trigger internal methods of components, such as submitting forms, displaying popups, etc. You can call component methods using $w.componentId.methodName, such as $w.form1.submit()

Method Name
Method Identifier
Parameters
Method Description
设置值setValueobject
  • value: object
    • address: string

      地点名称

    • geopoint: object

      经纬度

      • type: string Default value: 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

Through the Style API, you can override the styles of internal elements in components to achieve customization. For example, in the low-code editor, you can write styles for all button components using #wd-page-root .wd-btn, and control individual component styles with :scope. For detailed instructions, please refer toStyle API

Name
Class Name
Description and Examples
根元素.wd-location-root组件最外层元素
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-location-root {
  /* Write CSS styles here */
}
H5 端根元素.wd-h5-location-root可设定 H5 端的根元素样式
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-h5-location-root {
  /* Write CSS styles here */
}
PC 端根元素.wd-pc-location-root可设定 PC 端的根元素样式
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-pc-location-root {
  /* Write CSS styles here */
}
小程序端根元素.wd-mp-location-root可设定小程序端的根元素样式
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-mp-location-root {
  /* Write CSS styles here */
}
组件标题样式.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;
  }

Learn about Style API

Version Changes

  • Property changes
  • Style changes
  • widget api changes