
# 开启持续定位
1. 开始持续定位后，如果中间需要触发单点定位，需要先停掉持续定位；
2. 单点定位完成后，需要重新开始持续定位，单点定位和持续定位，只能串行使用。
#### 请求参数
| **参数**            | **类型**   | **必填** | **说明**                                                                                                          |
|:---|:---|:---|:---|
| type              | Number   | 否      | 0：默认，获取经纬度； 1：获取经纬度和详细到区县级别的逆地理编码数据                                                                             |
| mode              | String   | 否      | 设置定位类型，gps：GPS定位；hybrid：混合定位；默认为hybrid（gps 只返回经纬度，会覆盖type为1）（仅Android）                                          |
| interval          | Number   | 否      | 时间间隔，默认为2000ms，最低1000ms（仅Android）                                                                               |
| distanceFilter    | Number   | 否      | 定位最小更新距离：distanceFilter，单位：米，默认：0即位置有变化则返回 （仅iOS）                                                               |
| supportBackground | Number   | 否      | 该字段仅Android生效，支持WeLink切换到后台后仍可持续定位，0：表示WeLink在前台使用时持续定位；1：表示WeLink在前台使用、被切换到后台或息屏时都可以持续定位（部分Android手机有效）；默认值为：0 |
| onLocationChange  | Function | 否      | 持续回调函数                                                                                                          |
| onError           | Function | 否      | 持续定位错误回调函数                                                                                                      |
   
注意：
- Android机型mode 为gps时不返回逆地理编码数据，即使type为1也不返回逆地理编码数据
- supportBackground iOS：暂不支持，Android：受限于Android手机厂商对切后台的应用的管理策略，该参数设置为1不确保WeLink切后台后能持续定位，请谨慎使用。
onLocationChange#Object 持续定位返回结果
| **参数**    | **类型** | **描述**            |
|:---|:---|:---|
| longitude | Number | 经度                |
| latitude  | Number | 纬度                |
| accuracy  | Number | 精度                |
| provider  | String | 定位方式（仅Android）    |
| sp        | String | 速度                |
| ag        | String | 角度                |
| tm        | String | 时间                |
| address   | String | 地址（type为1生效）      |
| country   | String | 国家（type为1生效）      |
| province  | String | 省/直辖市（type为1生效）   |
| city      | String | 国家（type为1生效）      |
| cityCode  | String | 城市编码（type为1生效）    |
| district  | String | 区（type为1生效）       |
| adCode    | String | 区域编码（type为1生效）    |
| street    | String | 街道名称（type为1生效）    |
| streetNum | String | 门牌号（type为1生效）     |
| poiName   | String | 兴趣点名称（type为1生效）   |
| aoiName   | String | 所属兴趣点名称（type为1生效） |
   
#### 返回结果 .then
| **参数** | **类型** | **描述**       |
|:---|:---|:---|
| status | String | '1'，开启持续定位成功 |
   
#### 返回结果 .catch
| **参数**  | **类型** | **说明** |
|:---|:---|:---|
| code    | String | 错误码    |
| message | String | 错误描述   |
   
#### 请求示例
- ES6示例
```
// 开启持续定位
HWH5.startLocationUpdate({
  type: 1,
  mode: 'hybrid',
  interval: 2000,
  distanceFilter: 10,
  supportBackground:1,
  onLocationChange: (data) => {
    // {
    //   latitude: 22.6094081,
    //   longitude: 114.029265,
    //   adCode: '440309',
    //   address: '广东省深圳市xxx',
    //   aoiName: '深圳北站',
    //   city: '深圳市',
    //   cityCode: '0755',
    //   country: '中国',
    //   district: '龙华区',
    //   poiName: '深圳北站',
    //   province: '广东省',
    //   street: '致远中路',
    //   streetNum: '28号'
    // }
    console.log('onLocationChange = ', data);
  },
  onError: (error) => {
    console.log('onError = ', data);
  }
}).then((data) => {
  // { status: '1' }
  console.log('startLocationUpdate success = ', data);
}).catch((error) => {
  console.log('startLocationUpdate error = ', error);
});
 
// 结束持续定位
HWH5.stopLocationUpdate();
```
- ES5示例
```
// 开启持续定位
HWH5.startLocationUpdate({
  type: 1,
  mode: 'hybrid',
  interval: 2000,
  distanceFilter: 10,
  supportBackground:1,
  onLocationChange: (data) => {
    // {
    //   latitude: 22.6094081,
    //   longitude: 114.029265,
    //   adCode: '440309',
    //   address: '广东省深圳市xxx',
    //   aoiName: '深圳北站',
    //   city: '深圳市',
    //   cityCode: '0755',
    //   country: '中国',
    //   district: '龙华区',
    //   poiName: '深圳北站',
    //   province: '广东省',
    //   street: '致远中路',
    //   streetNum: '28号'
    // }
    console.log('onLocationChange = ', data);
  },
  onError: function(error) {
    console.log('onError = ', data);
  }
}).then(function(data) {
  // { status: '1' }
  console.log('startLocationUpdate success = ', data);
}).catch(function(error) {
  console.log('startLocationUpdate error = ', error);
});
 
// 结束持续定位
HWH5.stopLocationUpdate();
```
**HWH5.stopLocationUpdate**
[支持版本\>=10.5.2](https://open.welink.huaweicloud.com/docs/#/990hh0/whokyc/fa5obu)
