Geolocation
Start from API_LEVEL
2.1
. Please refer to API_LEVEL.
Geolocation Sensor.
info
permission code: device:os.geolocation
Methods
start
Start listening to location data
start(): void
stop
Stop listening to location data
stop(): void
getStatus
Get the positioning status, return A
for positioning in progress, return V
for invalid positioning
getStatus(): string
getLatitude
Get Latitude
getLatitude(option: Option): Result
Option
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
format | string | N | DMS | Coordinate format, optionally DD for decimal or DMS in degrees, minutes and seconds | 2.1 |
Result
Type | Description |
---|---|
number|DMS | Coordinates, coordinate system type WGS-84 |
DMS
Property | Type | Description | API_LEVEL |
---|---|---|---|
direction | string | Direction, N for north latitude, S for south latitude | 2.1 |
degrees | number | degree | 2.1 |
minutes | number | minute | 2.1 |
seconds | number | second | 2.1 |
getLongitude
Get Longitude
getLongitude(option: Option): Result
Option
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
format | string | N | DMS | Coordinate format, optionally DD for decimal or DMS in degrees, minutes and seconds | 2.1 |
Result
Type | Description |
---|---|
number|DMS | Coordinates, coordinate system type WGS-84 |
DMS
Property | Type | Description | API_LEVEL |
---|---|---|---|
direction | string | Direction, E for east longitude, W for west longitude | 2.1 |
degrees | number | degree | 2.1 |
minutes | number | minute | 2.1 |
seconds | number | second | 2.1 |
getSetting
Start from API_LEVEL
3.0
Get the positioning settings
getSetting(): Result
Result
Property | Type | Description | API_LEVEL |
---|---|---|---|
mode | number | Positioning settings, see mode below for value descriptions | 3.0 |
mode
Value | Type | Description | API_LEVEL |
---|---|---|---|
0 | number | Accuracy | 3.0 |
1 | number | Automation | 3.0 |
2 | number | Balance | 3.0 |
3 | number | Power Saving | 3.0 |
4 | number | Super Power Saving | 3.0 |
5 | number | Custom | 3.0 |
onChange
Register a callback function to listen for location information change events
onChange(callback: () => void): void
offChange
Cancel the callback function for listening to the location information change event
offChange(callback: () => void): void
onGnssChange
Start from API_LEVEL
3.0
Register a callback function to listen for GNSS information change events
onGnssChange(callback: (info: Info) => void): void
Info
Property | Type | Description | API_LEVEL |
---|---|---|---|
agps_inject_time | number | AGPS update time UTC timestamp in milliseconds | 3.0 |
top4_cn_val | number | Signal strength value of the positioning satellite | 3.0 |
is_dualband | number | Whether dual-band | 3.0 |
nb_valid_satellite | number | Number of available satellites | 3.0 |
nb_used_satellite | number | Number of satellites used | 3.0 |
elapsed_time | number | Time consumed from the start of satellite search to successful positioning, in seconds | 3.0 |
satellite_data | Array<SatelliteSystem> | Satellite data arrays | 3.0 |
SatelliteSystem
Property | Type | Description | API_LEVEL |
---|---|---|---|
gnss_id | number | Satellite ID, see gnss_id below for value descriptions | 3.0 |
sub_top4_cn_val | number | The strongest signal value of this satellite system | 3.0 |
nb_valid_satellite | number | Number of available satellites that can be searched | 3.0 |
gsv_data | Array<Satellite> | Single satellite data array, maximum length 32 | 3.6 |
gnss_id
Value | Type | Description | API_LEVEL |
---|---|---|---|
0 | number | GPS | 3.0 |
1 | number | BDS | 3.0 |
2 | number | GLONASS | 3.0 |
3 | number | GALILEO | 3.0 |
4 | number | QZSS | 3.0 |
5 | number | IRNSS | 3.0 |
Satellite
Property | Type | Description | API_LEVEL |
---|---|---|---|
id | number | Satellite ID | 3.6 |
elevation | number | Pitch angle | 3.6 |
azimuth | number | Azimuth | 3.6 |
snr | number | Signal-to-noise ratio | 3.6 |
offGnssChange
Start from API_LEVEL
3.0
Cancel the callback function for listening to the GNSS information change event
offGnssChange(callback: (...args: any[]) => any): void
Example
import { Geolocation } from '@zos/sensor'
const geolocation = new Geolocation()
const callback = () => {
if (geolocation.getStatus() === 'A') {
console.log(geolocation.getLatitude())
console.log(geolocation.getLongitude())
}
}
geolocation.start()
geolocation.onChange(callback)
// When not needed for use
geolocation.offChange(callback)
geolocation.stop()