原子操作

飞道科技

@dfeidao/atom-mobile > 地理位置API

External module: 地理位置API

Index

Functions


Functions

clear_watch

clear_watch(watchID: number): void

Defined in location/clear-watch.ts:23

description: 注销之前注册的监听位置更改

devdependencies: yarn add –dev @react-native-community/geolocation@1.4.1

devdependencies: yarn add –dev react-native-permissions@1.1.1

devdependencies: yarn add –dev @types/react-native-permissions@1.1.1

link: react-native link @react-native-community/geolocation

link: react-native link react-native-permissions

permission:

example: import clear_watch from ‘‘@dfeidao/atom-mobile/location/clear-watch’;

const watch_id = local_get(fd, ‘watch_id’); clear_watch(watch_id);

Parameters:

Name Type Description
watchID number number 即watch_position返回的值

Returns: void


distance

distance(from: [number, number], to: [number, number], units?: “degrees” | “radians” | “miles” | “kilometers”): number

Defined in location/distance.ts:17

description: 计算两坐标距离

devdependencies: yarn add –dev @turf/distance@6.0.1

devdependencies: yarn add –dev @turf/helpers@6.1.4

example: distance([-75.343, 39.984], [-75.534, 39.123], ‘miles’);

Parameters:

Name Type Description
from [number, number] 起点坐标[经度,纬度], 例如[-75.343, 39.984]。请注意经纬度前后次序。
to [number, number] 终点坐标[经度,纬度], 例如[-75.534, 39.123]。请注意经纬度前后次序。
Optional units “degrees” | “radians” | “miles” | “kilometers” 距离单位。可选值:’degrees’ | ‘radians’ | ‘miles’ | ‘kilometers’, 分别代表:角度|弧度|英里|千米

Returns: number


get_current_position

get_current_position(options: GeolocationOptions): Promise<object>

Defined in location/get-current-position.ts:53

description: 获取最新的位置信息,速度最快,但精度低

devdependencies: yarn add –dev @react-native-community/geolocation@1.4.1

devdependencies: yarn add –dev react-native-permissions@1.1.1

devdependencies: yarn add –dev @types/react-native-permissions@1.1.1

link: react-native link @react-native-community/geolocation

link: react-native link react-native-permissions

permission:

example: import get_current_position from ‘@dfeidao/atom-mobile/location/get-current-position’;

const latest = await (async () => { try { const position_options = { timeout: 500, maximumAge: 500, enableHighAccuracy: true, distanceFilter: 5, useSignificantChanges: false }; const res = await get_current_position(fd, position_options); return res.coords; } catch (error) { return { latitude: null, longitude: null, altitude: null, accuracy: null, altitudeAccuracy: null, heading: null, speed: null }; } })(); console.log(‘当前位置: ‘, latest);

Parameters:

Name Type
options GeolocationOptions

Returns: Promise<object>


watch_position

watch_position(fd: IFeidaoAiMobile, options: GeolocationOptions, success_event_name: string, error_event_name: string): Promise<number>

Defined in location/watch-position.ts:53

description: 注册监听位置更改,在注销之前会多次触发回调

devdependencies: yarn add –dev @react-native-community/geolocation@1.4.1

devdependencies: yarn add –dev react-native-permissions@1.1.1

devdependencies: yarn add –dev @types/react-native-permissions@1.1.1

link: react-native link @react-native-community/geolocation

link: react-native link react-native-permissions

permission:

example: import watch_position from ‘@dfeidao/atom-mobile/location/watch-position’; import local_set from ‘@dfeidao/atom-mobile/local/set’; const position_options = { timeout: 500, maximumAge: 500, enableHighAccuracy: true, distanceFilter: 5, useSignificantChanges: false }; const watch_id = await watch_position(fd, position_options, ‘a002’, ‘a004’); local_set(fd, ‘watch_id’, watch_id);

import local_get from ‘@dfeidao/atom-mobile/local/get’; import clear_watch from ‘@dfeidao/atom-mobile/location/clear-watch’; const watch_id = local_get(fd, ‘watch_id’); clear_watch(watch_id);

Parameters:

Name Type
fd IFeidaoAiMobile
options GeolocationOptions
success_event_name string
error_event_name string

Returns: Promise<number> watchID number clear-watch时用到