更新记录
1.0.0(2025-06-16)
- 【新增】初始化第一版本
- 【新增】申请权限,基础定位,停止定位,支持高度配置
平台兼容性
云端兼容性
uni-app(4.63)
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-vue插件版本 |
app-nvue |
app-nvue插件版本 |
Android |
Android插件版本 |
iOS |
鸿蒙 |
- |
- |
- |
- |
√ |
1.0.0 |
√ |
1.0.0 |
5.0 |
1.0.0 |
- |
- |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.63)
Chrome |
Safari |
Android |
Android插件版本 |
iOS |
鸿蒙 |
微信小程序 |
- |
- |
5.0 |
1.0.0 |
- |
- |
- |
Turbo UI 系列插件 - 高德定位SDK
- 如您已购买
Turbo UI
,那么该插件可以免费使用源码版!
- 使用需要打自定义基座,最新支持4.71,4.66,4.63版本,其他自测
- 支持单次定位,持续定位,场景定位,停止定位,销毁实例
使用示例
-
Turbo UI
示例 + uni-app x
版本
<template>
<t-navbar title="高德定位" :is-back="true"></t-navbar>
<!-- #ifdef APP -->
<scroll-view style="flex: 1;">
<!-- #endif -->
<t-card title="定位信息">
<t-text :ma="[5,0]">经度:{{data.longitude}}</t-text>
<t-text :ma="[5,0]">纬度:{{data.latitude}}</t-text>
<t-text :ma="[5,0]">地址信息:{{data.address}}</t-text>
<t-text :ma="[5,0]">国家:{{data.country}}</t-text>
<t-text :ma="[5,0]">省:{{data.province}}</t-text>
<t-text :ma="[5,0]">市:{{data.city}}</t-text>
<t-text :ma="[5,0]">区:{{data.district}}</t-text>
<t-text :ma="[5,0]">街道:{{data.street}}</t-text>
<t-text :ma="[5,0]">城市编码:{{data.cityCode}}</t-text>
<t-text :ma="[5,0]">地区编码:{{data.adCode}}</t-text>
</t-card>
<t-card title="接口">
<t-button :ma="[10,0]" type="primary" @click="requestPermission">申请权限</t-button>
<t-button :ma="[10,0]" type="primary" @click="getLocation">开启定位</t-button>
<t-button :ma="[10,0]" type="primary" @click="stopLocation">停止定位</t-button>
</t-card>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
// #ifdef APP
import { TALocationApi,TALocationOptions,TALocationResult,TALocationData } from "@/uni_modules/t-alocation-api"
const tALocationApi = new TALocationApi()
const data = ref<TALocationData>({
})
// #endif
import { reactive } from 'vue'
type stateType = {
loading: boolean;
}
const state = reactive<stateType>({
loading: false
})
const getLocation = () => {
// #ifdef APP
tALocationApi.getLocation({
once: true,
needAddress: true,
isWifiActiveScan: true,
success: (result: TALocationResult) => {
console.log(result)
data.value.address = result.data?.address
data.value.latitude = result.data?.latitude
data.value.longitude = result.data?.longitude
data.value.country = result.data?.country
data.value.province = result.data?.province
data.value.city = result.data?.city
data.value.district = result.data?.district
data.value.street = result.data?.street
data.value.adCode = result.data?.adCode
data.value.cityCode = result.data?.cityCode
},
fail: (result: TALocationResult) => {
console.log(result)
}
} as TALocationOptions)
// #endif
}
const stopLocation = () => {
// #ifdef APP
tALocationApi.stopLocation({
success: (result: TALocationResult) => {
console.log(result)
},
fail: (result: TALocationResult) => {
console.log(result)
}
} as TALocationOptions)
// #endif
}
const requestPermission = () => {
// #ifdef APP
tALocationApi.requestPermission({
success: (result:TALocationResult) => {
console.log(result)
},
fail: (result: TALocationResult) => {
console.log(result)
}
} as TALocationOptions)
// #endif
}
onReady(() => {
// #ifdef APP
TALocationApi.updatePrivacyAgree(true)
TALocationApi.updatePrivacyShow(true,true)
// #endif
state.loading = true
})
</script>
<script setup>
import { TALocationApi,TALocationOptions,TALocationResult,TALocationData } from "@/uni_modules/t-alocation-api"
const getLocation = () => {
tALocationApi.getLocation({
once: true,
needAddress: true,
isWifiActiveScan: true,
success: (result) => {
data.value.address = result.data.address
data.value.latitude = result.data.latitude
data.value.longitude = result.data.longitude
data.value.country = result.data.country
data.value.province = result.data.province
data.value.city = result.data.city
data.value.district = result.data.district
data.value.street = result.data.street
data.value.adCode = result.data.adCode
data.value.cityCode = result.data.cityCode
},
fail: (result) => {
console.log(result)
}
})
}
const stopLocation = () => {
tALocationApi.stopLocation({
success: (result) => {
console.log(result)
},
fail: (result) => {
console.log(result)
}
})
}
const requestPermission = () => {
tALocationApi.requestPermission({
success: (result) => {
console.log(result)
},
fail: (result) => {
console.log(result)
}
})
}
onReady(() => {
TALocationApi.updatePrivacyAgree(true)
TALocationApi.updatePrivacyShow(true,true)
})
</script>
暴露的类型
/**
* @description 定位数据
* @property {Number} latitude 纬度
* @property {Number} longitude 经度
* @property {String} address 地址信息
* @property {String} country 国家
* @property {String} province 省
* @property {String} city 市
* @property {String} district 区县
* @property {String} street 街道
* @property {Number} cityCode 城市编码
* @property {Number} adCode 地区编码
*/
export type TALocationData = {
latitude?: number;
longitude?: number;
address?: string;
country?: string;
province?: string;
city?: string;
district?: string;
street?: string;
adCode?: string;
cityCode?: string;
}
/**
* @description 返回
* @property {Number} code 状态码
* @property {String} msg 状态消息
* @property {TALocationData} data 定位数据
*/
export type TALocationResult = {
code: number;
msg: string;
data?: TALocationData
}
/**
* @description 参数配置
* @property {Number} locationMode 定位模式
* @value 1 高精度
* @value 2 低消耗
* @value 3 仅设备
* @property {Boolean} once 单次定位,不能与onceLatest同时使用
* @property {Boolean} onceLatest 单次高精度定位,不能与once同时使用
* @property {Number} interval 连续定位间隔时间,单位ms,默认2000
* @property {Boolean} needAddress 是否返回地址描述,默认true
* @property {Boolean} mockEnable 设置是否允许模拟位置,默认为true
* @property {Boolean} httpTimeOut 设置定位请求超时时间,默认为30秒,单位ms
* @property {Boolean} locationCacheEnable 设置是否开启定位缓存机制
* @property {Boolean} isWifiActiveScan 是否会主动刷新设备wifi模块,获取到最新鲜的wifi列表(wifi新鲜程度决定定位精度);false表示不主动刷新。
* @property {Number} protocol 用于设定网络定位时所采用的协议,提供http/https两种协议。
* @value 1 HTTP
* @value 2 HTTPS
*/
export type TALocationOptions = {
locationMode?: number;
once?: boolean;
onceLatest?: boolean;
interval?: number;
needAddress?: boolean;
mockEnable?: boolean;
httpTimeOut?: boolean;
locationCacheEnable?: boolean;
isWifiActiveScan?: boolean;
protocol?: number;
success?: (result: TALocationResult) => void;
fail?: (result: TALocationResult) => void;
}