Geolocation
Geolocation
Importing Modules
import geolocation from '@system.geolocation';
Developers need to declare the application's access permission for watch.permission.LOCATION in the manifest.json file.
API Definitions
getLocation
Gets the current latitude and longitude, returning an asynchronous location information.
subscribe
Watches for location changes. The location parameter of the callback is the current location information. The ID returned by this method can be used with the unsubscribe() method to stop watching.
unsubscribe
Stops watching for location changes.
Type Definitions
Location
Used to represent location information data.
type Location = {
code: number; // Location status code, indicating whether the current
// location information is valid
msg: string; // Location error message
data: {
// Location information data
longitude: number; // Latitude value
latitude: number; // Longitude value
coordType: string; // Coordinate system type, such as 'WGS84', 'GCJ02', etc.
};
};
The location status codes for the code field are as follows:
200: Current location information is valid;1002: Not currently connected to the phone's Bluetooth network1300: Phone cannot obtain location services1301: Location services are not enabled on the phone1302: Phone application has not been granted location permission1399: Unknown error
