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

兼容端

安卓苹果Web鸿蒙小程序

使用示例

vue

<script setup lang="uts">
	import { TBaiduLocationApi,TBaiduLocationOptions,TBaiduLocationResult,TBaiduLocationData } from "@/uni_modules/t-baidu-location"
	const tBaiduLocationApi = new TBaiduLocationApi()
	
	const startLocation = () => {
		tBaiduLocationApi.getLocation({
			success: (result: TBaiduLocationResult) => {
			},
			fail: (result: TBaiduLocationResult) => {
				console.log(result)
			}
		} as TBaiduLocationOptions)
	}
	
	const stopLocation = () => {
		tBaiduLocationApi.stopLocation({
			success: (result: TBaiduLocationResult) => {
				console.log(result)
			},
			fail: (result: TBaiduLocationResult) => {
				console.log(result)
			}
		} as TBaiduLocationOptions)
	}
	
	const getSceneLocation =() => {
		tBaiduLocationApi.getSceneLocation({
			scene: 1,
			success: (result: TBaiduLocationResult) => {
				console.log(result)
			},
			fail: (result: TBaiduLocationResult) => {
				console.log(result)
			}
		} as TBaiduLocationOptions)
	}
	
	onReady(() => {
		TBaiduLocationApi.setKey("你的AK")
	})
</script>

暴露的类型

ts
/**
 * @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 {String} adcode adcode
 * @property {String} town 乡镇信息
 */
export type TBaiduLocationData = {
	latitude?: number;
	longitude?: number;
	address?: string;
	country?: string;
	province?: string;
	city?: string;
	district?: string;
	street?: string;
	adcode?: string;
	town?: string;
}
/**
 * @description 返回信息
 * @property {Number} code 状态码
 * @property {String} msg 状态消息
 * @property {TBaiduLocationData} data 定位数据
 */
export type TBaiduLocationResult = {
	code: number;
	msg: string;
	data?: TBaiduLocationData;
}
/**
 * @property {Number} mode 定位模式
 * @value 1 高精度
 * @value 2 低功耗
 * @value 3 仅使用设备
 * @value 4 模糊定位模式
 * @property {String} coorType 经纬度坐标类型
 * @value gcj02 国测局坐标
 * @value bd09ll 百度经纬度坐标
 * @value bd09 百度墨卡托坐标
 * @property {Boolean} needAddress 是否需要地址信息
 * @property {Boolean} needNewVersionRgc 设置是否需要最新版本的地址信息
 * @property {Boolean} needLocationDescribe 是否需要位置描述信息
 * @property {Boolean} needLocationPoiList 是否需要周边POI信息
 * @property {Number} scene 场景模式,仅场景定位有效
 * @value 1 签到场景
 * @value 2 运动场景
 * @value 3 出行场景
 */
export type TBaiduLocationOptions = {
	mode?: number;
	coorType?: "gcj02" | "bd09ll" | "bd09";
	needAddress?: boolean;
	needNewVersionRgc?: boolean;
	needLocationDescribe?: boolean;
	needLocationPoiList?: boolean;
	scene?: number;
	success?: (result: TBaiduLocationResult) => void;
	fail?: (result: TBaiduLocationResult) => void;
}