For the complete documentation index, see llms.txt. This page is also available as Markdown.

Device.getLocation

函数式 API getCurrentLocation也可以这样使用同样的功能。

功能说明

获取设备的当前位置一次。用于地图、天气、查找门店等需要当前位置时。若要持续检测位置变化, Device.subscribeLocation请使用它。

如果没有位置权限, GetCurrentLocationPermissionError会发生。 Device.getLocation.getPermission() / Device.getLocation.openPermissionDialog()可以用来确认并请求权限。

类型

Device.getLocation(options: GetCurrentLocationOptions): Promise<Location>;

Params

enum Accuracy {
  Lowest = 1, // 误差范围约 3KM 以内
  Low = 2, // 误差范围约 1KM 以内
  Balanced = 3, // 误差范围数百米以内
  High = 4, // 误差范围约 10M 以内
  Highest = 5,
  BestForNavigation = 6,
}

type GetCurrentLocationOptions = {
  accuracy: Accuracy;
};

Response

错误

错误会以类的形式抛出 — error instanceof GetCurrentLocationPermissionError来识别。该类可在 @apps-in-toss/web-framework中导入。

错误类
说明

GetCurrentLocationPermissionError

表示位置权限被拒绝。 Device.getLocation.openPermissionDialog()可以重新请求。

示例代码

这有帮助吗?