@warpsoft/geolocation
v0.2.49
Published
基于百度地图位置服务的定位插件
Readme
@warpsoft/geolocation
基于百度地图位置服务的定位插件
Install
npm install @warpsoft/geolocation
npx cap synciOS
Apple 需要在Info.plist文件中指定获取位置隐私的描述
- NSLocationAlwaysUsageDescription (Privacy - Location Always Usage Description)
- NSLocationWhenInUseUsageDescription (Privacy - Location When In Use Usage Description)
百度地图 需要在Info.plist文件中指定 key
- BMKLocationKey 2LiwwO3SQoYOSoF1lYwAdpc8TkauXpki
Android
百度地图 需要在 AndroidMenifest.xml 中指定 key
<application>
...
+ <meta-data
+ android:name="com.baidu.lbsapi.API_KEY"
+ android:value="2LiwwO3SQoYOSoF1lYwAdpc8TkauXpki" >
+ </meta-data>
...
</application>API
getCurrentLocation(...)
getCurrentLocation(options: requestOptions) => Promise<Position>获取当前位置信息
| Param | Type | Description |
| ------------- | --------------------------------------------------------- | ----------- |
| options | requestOptions | 请求位置信息的选项 |
Returns: Promise<Position>
watchLocation(...)
watchLocation(options: requestOptions, callback: Function) => Promise<void>连续获取位置信息
| Param | Type | Description |
| -------------- | --------------------------------------------------------- | ----------- |
| options | requestOptions | 请求位置信息的选项 |
| callback | Function | 处理位置信息的回调函数 |
watchStatus()
watchStatus() => Promise<Status>获取监视状态
Returns: Promise<Status>
clearWatch()
clearWatch() => Promise<void>清除位置监视
Interfaces
Position
当前位置信息
| Prop | Type | Description |
| ------------ | --------------------------------------------------- | ----------- |
| time | string | 获取时间 |
| coords | Coordinates | 坐标信息 |
| addr | Address | 地址信息 |
Coordinates
地理坐标详细信息
| Prop | Type | Description |
| --------------- | ------------------- | ----------- |
| latitude | number | 经度 |
| longitude | number | 纬度 |
| altitude | number | 高度 |
| speed | number | 速度 |
| direction | number | 方向 |
| radius | number | 半径 |
Address
地址中文详细信息
| Prop | Type | Description |
| -------------- | ------------------- | ----------- |
| country | string | 国家 |
| adcode | string | 地区编码 |
| province | string | 省 |
| city | string | 市 |
| district | string | 区 |
| street | string | 街道 |
| address | string | 地址描述 |
| town | string | 村镇 |
requestOptions
请求位置信息的选项
| Prop | Type | Description |
| ------------------- | -------------------- | ----------- |
| withReGeocode | boolean | 是否携带地址详细信息 |
Function
Creates a new function.
| Prop | Type |
| --------------- | --------------------------------------------- |
| prototype | any |
| length | number |
| arguments | any |
| caller | Function |
| Method | Signature | Description | | ------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | apply | (this: Function, thisArg: any, argArray?: any) => any | Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function. | | call | (this: Function, thisArg: any, ...argArray: any[]) => any | Calls a method of an object, substituting another object for the current object. | | bind | (this: Function, thisArg: any, ...argArray: any[]) => any | For a given function, creates a bound function that has the same body as the original function. The this object of the bound function is associated with the specified object, and has the specified initial parameters. | | toString | () => string | Returns a string representation of a function. |
Status
位置监视状态
| Prop | Type | Description |
| -------------- | -------------------- | ---------------------------- |
| watching | boolean | 是否正在监视 |
| id | string | 监视id 可用来 clearWatch 停止监视位置信息 |
