Skip to content
广告位招租广告位招租

兼容端

安卓苹果Web鸿蒙小程序

配置

tALocationApi.setKey("你的key")

使用示例 - uni-app x 版本

vue

<script setup lang="uts">
	import * as tALocationApi from "@/uni_modules/t-alocation-api"

	const getLocation = () => {
		tALocationApi.getLocation({
			once: true,
			needAddress: true,
			isWifiActiveScan: true,
			success: (result: tALocationApi.TALocationResult) => {
				console.log(result)
			},
			fail: (result: tALocationApi.TALocationResult) => {
				console.log(result)
			}
		} as tALocationApi.TALocationOptions)
	}
	const stopLocation = () => {
		tALocationApi.stopLocation({
			success: (result: tALocationApi.TALocationResult) => {
				console.log(result)
			},
			fail: (result: tALocationApi.TALocationResult) => {
				console.log(result)
			}
		} as tALocationApi.TALocationOptions)
	}
	
	
	const requestPermission = () => {
		tALocationApi.requestPermission({
			success: (result: tALocationApi.TALocationResult) => {
				console.log(result)
			},
			fail: (result: tALocationApi.TALocationResult) => {
				console.log(result)
			}
		} as tALocationApi.TALocationOptions)
	}
	onReady(() => {
		tALocationApi.updatePrivacyAgree(true)
		tALocationApi.updatePrivacyShow(true,true)
		tALocationApi.setKey("")
	})
</script>

暴露的类型

ts
/**
 * @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;
}