25 lines
676 B
TypeScript
25 lines
676 B
TypeScript
import { getWechatLocation } from '@dukang/weixin-sdk';
|
|
import { weixinSdk } from './weixin';
|
|
|
|
export type ClientGpsLocation = {
|
|
province?: string;
|
|
city?: string;
|
|
district?: string;
|
|
latitude: number;
|
|
longitude: number;
|
|
address?: string;
|
|
};
|
|
|
|
/** 尝试获取客户端 GPS(微信优先,其次 H5 Geolocation),失败返回 null 不阻塞下单 */
|
|
export async function tryGetClientGpsLocation(): Promise<ClientGpsLocation | null> {
|
|
const loc = await weixinSdk.getLocation();
|
|
if (!loc) return null;
|
|
return {
|
|
latitude: loc.latitude,
|
|
longitude: loc.longitude,
|
|
};
|
|
}
|
|
|
|
/** @deprecated 使用 tryGetClientGpsLocation */
|
|
export { getWechatLocation };
|