> For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt.

# onLocationChangeError

注册位置更新异常回调。

## 支持版本

前端库版本不低于 `0.0.32`。

## 支持平台

<table>
<thead>
<tr><th>平台</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>Android</td><td>支持</td></tr>
<tr><td>iOS</td><td>支持</td></tr>
<tr><td>PC</td><td>不支持</td></tr>
<tr><td>HarmonyOS</td><td>不支持</td></tr>
</tbody>
</table>

## 支持场景

<table>
<thead>
<tr><th>场景</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>页面</td><td>支持</td></tr>
<tr><td>卡片</td><td>不支持</td></tr>
</tbody>
</table>

## 使用说明

- 建议在调用 `startLocationUpdate` 前注册；不再使用时调用返回的取消函数释放当前监听

## 调用方式

### 事件监听 API

```typescript
onLocationChangeError(callback: LocationChangeErrorListener): () => void
```

## 入参

无。

## 调用示例

```typescript
import { onLocationChangeError } from '@doubao-dev/framework/api';

const unsubscribe = onLocationChangeError(({ errMsg, errCode }) => {
  console.log(errMsg, errCode);
});

unsubscribe();
```

## 回调参数

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必返</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>event.errCode</code></td><td><code>number</code></td><td>否</td><td>错误码</td></tr>
<tr><td><code>event.errMsg</code></td><td><code>string</code></td><td>是</td><td>错误信息</td></tr>
</tbody>
</table>

## 返回值

返回取消当前监听函数的函数。

### 回调示例

```json
{
  "errMsg": "location_timeout",
  "errCode": 0
}
```

## 错误处理

错误对象和通用错误码见 [通用错误处理](/apps-plugin/docs/js-api/common-errors.md#错误返回)。

### 失败示例

```json
{
  "errMsg": "location_timeout",
  "errCode": 0
}
```

### 错误码

#### 事件错误码

<table>
<thead>
<tr><th>错误字段</th><th>值</th><th>错误信息</th><th>平台</th><th>触发条件</th><th>处理建议</th></tr>
</thead>
<tbody>
<tr><td><code>event.errCode</code></td><td><code>0</code></td><td>-</td><td>Android</td><td>持续定位过程中发生异常</td><td>结合 errMsg 检查系统定位服务、权限和网络环境</td></tr>
<tr><td><code>event.errCode</code></td><td><code>0</code></td><td><code>location_timeout</code></td><td>iOS</td><td>系统定位超时</td><td>稍后重试，并检查定位环境</td></tr>
<tr><td><code>event.errCode</code></td><td><code>1</code></td><td><code>location_service_disabled</code></td><td>iOS</td><td>系统定位服务已关闭</td><td>在系统设置中开启定位服务</td></tr>
<tr><td><code>event.errCode</code></td><td><code>25</code></td><td><code>location_permission_denied</code></td><td>iOS</td><td>尚未完成系统定位授权</td><td>重新发起授权后重试</td></tr>
<tr><td><code>event.errCode</code></td><td><code>27</code></td><td><code>location_permission_denied</code></td><td>iOS</td><td>用户拒绝系统定位权限</td><td>引导用户在系统设置中开启定位权限</td></tr>
<tr><td><code>event.errCode</code></td><td><code>29</code></td><td><code>location_permission_denied</code></td><td>iOS</td><td>系统限制定位权限</td><td>提示用户检查系统限制设置</td></tr>
</tbody>
</table>

## 平台差异

- **iOS**：其他系统定位异常会保留原始 errCode 并返回 location\_fail；位置结果无效时事件中可能不包含 errCode
