更新记录
1.0.0(2025-03-11)
下载此版本
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 4.32,Android:支持,iOS:支持,HarmonyNext:不确定 |
× |
√ |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
kux-apiuse-getLocation
该插件是 uni.getLocation 的异步版本封装,在支持原生API所有特性前提下可以使用异步hooks函数实现业务逻辑,使业务代码更简洁高效。
插件特色
基本用法
import { useGetLocation } from '@/uni_modules/kux-apiuse-getLocation';
const { getLocation } = useGetLocation();
const handleClick = async () => {
const { result, error } = await getLocation(null);
if (error != null) {
console.error('错误内容:', error);
return;
}
console.log('获取到的位置信息:', result);
};
注意
该插件运行环境要求需要uni编译器版本在 4.32
及以上
类型定义
/**
* interface.uts
* uts插件接口定义文件,按规范定义接口文件可以在HBuilderX中更好的做到语法提示
*/
export type KuxGetLocationReturn = {
result?: GetLocationSuccess | null;
error?: IGetLocationFail | null;
}
export type KuxAPIUseGetLocationReturn = {
getLocation: (options?: GetLocationOptions | null) => Promise<KuxGetLocationReturn>;
}
结语
友情推荐