Skip to main content
Version: v3+

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​

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
formatstringNDDCoordinate format, optionally DD for decimal or DMS in degrees, minutes and seconds2.1

Result​

TypeDescription
number|DMSCoordinates, coordinate system type WGS-84

DMS​

PropertyTypeDescriptionAPI_LEVEL
directionstringDirection, N for north latitude, S for south latitude2.1
degreesnumberdegree2.1
minutesnumberminute2.1
secondsnumbersecond2.1

getLongitude​

Get Longitude

getLongitude(option: Option): Result

Option​

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
formatstringNDDCoordinate format, optionally DD for decimal or DMS in degrees, minutes and seconds2.1

Result​

TypeDescription
number|DMSCoordinates, coordinate system type WGS-84

DMS​

PropertyTypeDescriptionAPI_LEVEL
directionstringDirection, E for east longitude, W for west longitude2.1
degreesnumberdegree2.1
minutesnumberminute2.1
secondsnumbersecond2.1

getSetting​

Start from API_LEVEL 3.0

Get the positioning settings

getSetting(): Result

Result​

PropertyTypeDescriptionAPI_LEVEL
modenumberPositioning settings, see mode below for value descriptions3.0

mode​

ValueTypeDescriptionAPI_LEVEL
0numberAccuracy3.0
1numberAutomation3.0
2numberBalance3.0
3numberPower Saving3.0
4numberSuper Power Saving3.0
5numberCustom3.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​

PropertyTypeDescriptionAPI_LEVEL
agps_inject_timenumberAGPS update time UTC timestamp in milliseconds3.0
top4_cn_valnumberSignal strength value of the positioning satellite3.0
is_dualbandnumberWhether dual-band3.0
nb_valid_satellitenumberNumber of available satellites3.0
nb_used_satellitenumberNumber of satellites used3.0
elapsed_timenumberTime consumed from the start of satellite search to successful positioning, in seconds3.0
satellite_dataArray<SatelliteSystem>Satellite data arrays3.0

SatelliteSystem​

PropertyTypeDescriptionAPI_LEVEL
gnss_idnumberSatellite ID, see gnss_id below for value descriptions3.0
sub_top4_cn_valnumberThe strongest signal value of this satellite system3.0
nb_valid_satellitenumberNumber of available satellites that can be searched3.0
gsv_dataArray<Satellite>Single satellite data array, maximum length 323.6

gnss_id​

ValueTypeDescriptionAPI_LEVEL
0numberGPS3.0
1numberBDS3.0
2numberGLONASS3.0
3numberGALILEO3.0
4numberQZSS3.0
5numberIRNSS3.0

Satellite​

PropertyTypeDescriptionAPI_LEVEL
idnumberSatellite ID3.6
elevationnumberPitch angle3.6
azimuthnumberAzimuth3.6
snrnumberSignal-to-noise ratio3.6

offGnssChange​

Start from API_LEVEL 3.0

Cancel the callback function for listening to the GNSS information change event

offGnssChange(callback: (info: Geolocation.onGnssChange.Info) => void): void

getEnabled​

Start from API_LEVEL 4.0

Get whether the user allows the Mini Program to use location features

getEnabled(): boolean

onEnableChange​

Start from API_LEVEL 4.0

Register a callback function to listen for user location permission change events

onEnableChange(callback: () => void): void

offEnableChange​

Start from API_LEVEL 4.0

Cancel the callback function for listening to user location permission change events

offEnableChange(callback: () => void): 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()