4.0.3 • Published 5 years ago

cordova-plugin-hms-location v4.0.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

cordova-plugin-hms-location

Contents

  1. Introduction
  2. Installation Guide
  3. Cordova Example API Method Definition
  4. Configure Description
  5. Licensing and Terms

1. Introduction

This Cordova SDK code encapsulates the Huawei Location Kit interface. It provides many APIs for your reference or use.

The package is described as follows:

  • src/main/com/huawei/hms/cordova/location: core layer that exposes LocationKitSDK functionality to JS side.
  • www/: Public interfaces for interacting LocationKitSDK through Cordova.

2. Installation Guide

  1. Download cordova-plugin-hms-location.
  2. Add Android platform to your project if you haven't yet.
cordova platform add android
  1. Add this plugin to your project by running the following command in root directory of your project:
cordova plugin add PATH_TO_CORDOVA_LOCATION_PLUGIN
  1. Run your app.
cordova run android

3. Cordova SDK API method definitions

Modules Overview

ModuleDescription
HMSLocationKitA module for initializing the package.
HMSFusedLocationWith this module you can check the device location settings, get the last known location information once or continuously, set mock location and others
HMSActivityIdentificationIf your app needs to obtain the activity status of the user's device (for example, walking, running, or bicycling) or your app needs to detect activity status change of a user, you can use this module.
HMSGeofenceIf you are interested in a place, you can create a geofence based on the place. When the device enters the geofence or stays for a duration of time, a notification can be sent to your app.

Common Functions

Return TypeFunction
voidregisterHMSEvent(eventName, handler)
voidunregisterHMSEvent(eventName, handler)

HMSLocationKit

Return TypeFunction
Promise<>init()

HMSFusedLocation

Data Types

LocationData
FieldType
latitudeFloatLatitude of a location. If no latitude is available, 0.0 is returned.
longitudeFloatLongitude of a location. If no longitude is available, 0.0 is returned.
speedFloatSpeed of a device at the current location, in meters per second. If no speed is available, 0.0 is returned.
bearingFloatBearing of a device at the current location, in degrees. If no bearing is available, 0.0 is returned.
accuracyFloatHorizontal error of a location, in meters. If no horizontal error is available, 0.0 is returned.
verticalAccuracyMetersFloatVertical error of a location, in meters. If no vertical error is available, 0.0 is returned.
bearingAccuracyDegreesFloatBearing error of the current location, in degrees. If no bearing error is available, 0.0 is returned.
speedAccuracyMetersPerSecondFloatSpeed error of a device at the current location, in meters per second. If no speed error is available, 0.0 is returned.
timeFloatCurrent timestamp, in milliseconds.
fromMockProviderBooleanIndicates whether location coming from mock provider.
LocationRequest
FieldTypeDescription
priorityNumberRequest priority. The default value is 100.
intervalFloatRequest interval, in milliseconds. The default value is 3600000.
numUpdatesNumberNumber of requested location updates.
fastestIntervalFloatShortest request interval, in milliseconds. The default value is 600000. If another app initiates a location request, the location is also reported to the app at the interval specified in fastestInterval.
expirationTimeFloatRequest expiration time, in milliseconds.
expirationTimeDurationFloatRequest expiration duration, in milliseconds.
smallestDisplacementFloatMinimum displacement between location updates, in meters.
maxWaitTimeFloatMaximum waiting timeIndicates whether to return the address information. The default value is false.
needAddressBooleanIndicates whether to return the address information. The default value is false.
languageStringLanguage. The value consists of two letters and complies with the ISO 639-1 international standard. By default, the value is empty.
countryCodeStringCountry code. The value consists of two letters and complies with the ISO 3166-1 international standard. By default, the value is empty.
LocationSettingsRequest
FieldsTypeDescription
locationRequestsLocationRequestCollection of LocationRequest object.
needBleBooleanIndicates whether BLE scanning needs to be enabled. The options are true (yes) and false (no).
alwaysShowBooleanIndicates whether a location is required for the app to continue. The options are true (yes) and false (no).
LatLng
FieldsTypeDescription
longitudefloatLongitude of a location.
latitudefloatLatitude of a location.
LocationAvailability
FieldsTypeDescription
isLocationAvailablebooleanIndicates if the location is available or not.
HasPermission
FieldsTypeDescription
hasPermissionbooleanIndicates if the permission is available or not.
RequestCode
FieldsTypeDescription
requestCodeThe request code.

Functions

Return TypeFunction
Promise<>init()
Promise<>flushLocations()
PromisecheckLocationSettings(locationRequest)
PromisegetLastLocation()
PromisegetLocationAvailability()
PromiseremoveLocationUpdates(requestCode)
PromiserequestLocationUpdates(locationRequest)
Promise<>setMockMode(isMockMode)
Promise<>setMockLocation(mockLocation)
PromisegetLastLocationWithAddress(locationRequest)
Promise<>requestPermission()
PromisehasPermission()

HMSActivityIdentification

Data Types

ActivityConversionInfo
FieldsTypeDescription
conversionTypeIntActivity conversion information. The options are Activities.ENTER_ACTIVITY_CONVERSION and Activities.EXIT_ACTIVITY_CONVERSION.
activityTypeIntActivity type. Please refer to Constants to see options.
ActivityConversionData
FieldsTypeDescription
conversionTypeIntActivity type. Please refer to Constants to see options.
elapsedTimeFromRebootFloatThe elapsed real time (in milliseconds) of this conversion since boot, including sleeping time obtained by SystemClock.elapsedRealtime().
conversionTypeIntActivity conversion information. The options are Activities.ENTER_ACTIVITY_CONVERSION and Activities.EXIT_ACTIVITY_CONVERSION.
ActivityConversionRequest
FieldsTypeDescription
conversionTypeIntConversion type.
activityTypeIntActivity type.
ActivityConversionResponse
FieldsTypeDescription
activityConversionDatasActivityConversionDataAll activity conversion events in the result. The obtained activity events are sorted by time in ascending order.
ActivityIdentificationData
FieldsTypeDescription
possibilityIntConfidence information.
identificationActivityIntDetected activity type.
ActivityIdentificationResponse
FieldsTypeDescription
elapsedTimeFromRebootIntThe elapsed real time (in milliseconds) of this detection since boot, including sleeping time obtained by SystemClock.elapsedRealtime().
mostActivityIdentificationIntThe most probable activity identification of the user.
activityIdentificationDatasActivityIdentificationDataThe list of activitiy identification list. The activity identifications are sorted by most probable activity first.
timeIntThe time of this identification, which is in milliseconds since January 1, 1970,obtained by System.currentTimeMillis().
HasPermission
FieldsTypeDescription
hasPermissionbooleanIndicates if the permission is available or not.
RequestCode
FieldsTypeDescription
requestCodeThe request code.

Functions

Return TypeFunction
Promise<>init()
PromisecreateActivityConversionUpdates(activityConversionRequest)
PromisecreateActivityIdentificationUpdates(intervalMillis)
Promise<>deleteActivityConversionUpdates(requestCode)
Promise<>deleteActivityIdentificationUpdates(requestCode)
Promise<>requestPermission()
PromisehasPermission()

HMSGeofence

Data Types

Geofence
FieldsTypeDescription
longitudeFloatLongitude. The value range is -180,180.
latitudeFloatLatitude. The value range is -90,90.
radiusFloatRadius, in meters.
uniqueIdStringUnique ID. If the unique ID already exists, the new geofence will overwrite the old one.
conversionsNumberGeofence conversions. The bitwise-OR operation is supported.
validContinueTimeFloatGeofence timeout interval, in milliseconds. The geofence will be automatically deleted after this amount of time.
dwellDelayTimeNumberGeofence timeout interval, in milliseconds. The geofence will be automatically deleted after this amount of time.
notificationIntervalNumberNotification response capability. The default value is 0. Setting it to a larger value can reduce power consumption accordingly. However, reporting of geofence events may be delayed.
GeofenceResponse
FieldsTypeDescription
uniqueIdStringUnique id
GeofenceData
FieldsType
convertingGeofenceListArrayInformation about converted geofences.
conversionNumberGeofence convert type.
convertingLocationArrayThe location when a geofence is converted.
errorCodeNumberError code. For details, please refer to Cordova Result Codes.
errorMessageStringDetailed error message.

Functions

Return TypeFunction
Promise<>init()
PromisecreateGeofenceList(geofenceRequest, initConversions, coordinateType)
Promise<>deleteGeofenceList(geofenceRequestId)

Usage Notes

By default every function returns a Promise. Alternatively you can use callback variations of these functions by prepending cb to the function name.

// async version
try {
   let result = await HMSFusedLocation.setMockMode(true);
   console.log(message);
} catch (err) {
   console.log(err);
}

// callback version
HMSFusedLocation.cbSetMockMode(true,
   (result) => { // Success callback
      console.log(result);
   },
   (err)=>{ // Error callback
      console.log(err);
   }
);

4. Configure Description

No.

5. Licensing and Terms

Apache 2.0 license.

4.0.3

5 years ago