> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/react-native/location.md).

# 位置

### 检测位置变更

**SDK 钩子：** `useGeolocation`

`useGeolocation`是一个返回设备位置信息的钩子。位置发生变化时，值也会变化。它利用 GPS 信息检测当前位置，并会随着用户移动自动更新。例如，可用于在地图类服务中显示用户当前位置，或在配送应用中追踪实时移动路线。它可以调整位置信息的精度和更新周期，因此既能将电量消耗降到最低，又能保持所需级别的精度。

**签名**

```typescript
function useGeolocation({ accuracy, distanceInterval, timeInterval }: UseGeolocationOptions): Location | null;
```

**参数**

* **options** · 必填 · `UseGeolocationOptions`

  这是位置信息检测所需的设置对象。

  * **options.accuracy** · `Accuracy`

    设置位置精度。 `Accuracy.Lowest`：误差范围在 3KM 以内， `Accuracy.Low`：误差范围在 1KM 以内， `Accuracy.Balanced`：误差范围在几百米以内， `Accuracy.High`：误差范围在 10M 以内， `Accuracy.Highest`：最高精度， `Accuracy.BestForNavigation`：适用于导航的最高精度
  * **options.timeInterval** · `number`

    以更新位置信息的最小周期为单位，单位为毫秒(ms)。此值设置位置信息更新发生的最短间隔，但受系统或环境影响，实际更新间隔可能会比指定周期更长。
  * **options.distanceInterval** · `number`

    将位置变化距离设置为米(m)单位。

**返回值**

* Location | null

  会返回包含设备位置信息的对象。详情请参见 [Location](/documentation/api-and-sdk-zh/common/permission/location.md)。

**示例**

**在屏幕上显示位置信息**

```tsx
import React, { useState, useCallback } from 'react';
import { View, Text } from 'react-native';
import { useGeolocation, Accuracy } from '@apps-in-toss/framework';

// 检测位置变更
function LocationWatcher() {
  const location = useGeolocation({
    accuracy: Accuracy.Balanced,
    distanceInterval: 10,
    timeInterval: 1000,
  });

  if (location == null) {
    return <Text>正在获取位置信息...</Text>;
  }

  return (
    <View>
      <Text>
        位置信息：{location.latitude}, {location.longitude}
      </Text>
    </View>
  );
}
```

**体验示例应用**

[apps-in-toss-examples](https://github.com/toss/apps-in-toss-examples) 在仓库中 [with-location-tracking](https://github.com/toss/apps-in-toss-examples/tree/main/with-location-tracking) 下载代码，或扫描下方二维码亲自体验。

二维码链接：intoss\://with-location-tracking


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/react-native/location.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
