

English
使用应用内置地图查看位置。openLocation会使用项目配置的地图服务商来展示地图,地图服务商支持情况参考:map组件。
Platform difference description
App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序、飞书小程序 | QQ小程序 | 快手小程序 | 京东小程序 | 元服务 | 小红书小程序 |
---|---|---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | √ | x | x | x | √ | √ |
HarmonyOS |
---|
HBuilderX 4.25 |
地图服务商说明
OBJECT parameter description
Parameter name | Type | Required | Instruction | Platform difference description |
---|---|---|---|---|
latitude | Float | Yes | Latitude, from -90 to 90. Negative number indicates south latitude, using gcj02 coordinate of State Bureau of Surveying and Mapping of China | |
longitude | Float | 是 | 经度,范围为-180~180,负数表示西经,使用 gcj02 国测局坐标系 | |
scale | Int | 否 | 缩放比例,范围5~18,默认为18 | 微信小程序、支付宝小程序 |
name | String | No | Location Name | Alipay Required |
address | String | No | Detailed description of the address | Alipay required |
success | Function | No | Callback function for successful interface calling | |
fail | Function | No | Callback function for failed interface calling | |
complete | Function | No | Callback function for closed interface calling (available both for successful and failed calling) |
Example
uni.getLocation({
success: function (res) {
const latitude = res.latitude;
const longitude = res.longitude;
uni.openLocation({
latitude: latitude,
longitude: longitude,
success: function () {
console.log('success');
}
});
}
});
Tips
<map>
component is defaulted to the coordinates of the State Bureau of Surveying and Mapping of China. When calling uni.getLocation
return result and passing it to the <map>
component, the type must be specified as gcj02.urlschemewhitelist
节点,在线打包即可{
"app-plus": {
"distribute": {
"ios": {
"urlschemewhitelist": [
"baidumap",
"iosamap",
"qqmap"
]
}
}
}
}
使用三方定位或者地图服务,需向服务提供商(如:高德地图、百度地图、腾讯地图、谷歌地图)申请商业授权和缴纳费用(5万/年)。
DCloud为开发者争取了福利,可优惠获取高德、腾讯的商业授权。如有需求请发邮件到bd@dcloud.io
(注明你的公司名称、应用介绍、HBuilder账户);你也可以直接通过uni-im
发起在线咨询,在线咨询地址:DCloud地图服务专员。
详见:https://uniapp.dcloud.net.cn/tutorial/app-geolocation.html#lic