English
Use the built-in map to view locations.
Platform difference description
App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序、飞书小程序 | QQ小程序 | 快手小程序 | 京东小程序 |
---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | √ | x | x | x |
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 | Yes | Longitude, from -180 to 180. Negative number indicates west longitude, using gcj02 coordinate of State Bureau of Surveying and Mapping of China. | |
scale | Int | No | Scale, the range is 5~18, the default is 18 | WeChat applet |
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({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
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