Huawei Location Kit Flutter Plugin

Table of Contents

Introduction

This plugin enables communication between Huawei Location SDK and Flutter platform. Huawei Location Kit combines the GPS, Wi-Fi, and base station locations to help you quickly obtain precise user locations, build up global positioning capabilities, and reach a wide range of users around the globe.Currently, it provides the four main capabilities: fused location, location semantics, activity identification, and geofence. You can call relevant capabilities as needed.

Huawei Location Kit provides the following core capabilities:

  • Fused location: Provides a set of simple and easy-to-use APIs for you to quickly obtain the device location based on the GPS, Wi-Fi, and base station location data.
  • Activity identification: Identifies user motion status through the acceleration sensor, cellular network information, and magnetometer, helping you adjust your app based on user behavior.
  • Geofence: Allows you to set an interested area through an API so that your app can receive a notification when a specified action (such as leaving, entering, or lingering in the area) occurs.

Installation Guide

  • Before you get started, you must register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.

  • Create an app in your project is required in AppGallery Connect in order to communicate with Huawei services. To create an app, perform the following steps:

Step 1. Sign in to AppGallery Connect and select My projects.

Step 2. Click your project from the project list.

Step 3. Go to Project Setting > General information, and click Add app. If an app exists in the project, and you need to add a new one, expand the app selection area on the top of the page and click Add app.

Step 4. On the Add app page, enter app information, and click OK.

  • A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core service through the HMS Core SDK. Before using HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in AppGallery Connect. Ensure that the JDK has been installed on your computer.

Configuring the Signing Certificate Fingerprint

Step 1: Go to Project Setting > General information. In the App information field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA256 certificate fingerprint.

Step 2: After completing the configuration, click OK. (Check mark icon)

Integrating Flutter Location Plugin

Step 1: Sign in AppGallery Connect to AppGallery Connect and select My projects.

Step 2: Find your app project, and click the desired app name.

Step 3: Go to Project Setting > > General information. In the App information field, click agconnect-service.json to download configuration file.

Step 4: Create a Flutter project if you do not have one.

Step 5: Copy the agconnect-service.json file to the android/app directory of your Flutter project.

Step 6: Copy the signature file that is generated in Generating a Signature File to the android/app directory of your Flutter project.

Step 7: Check whether the agconnect-services.json file and signature file are successfully added to the android/app directory of the Flutter project.

Step 8: Open the build.gradle file in the android directory of your Flutter project. - Go to buildscript then configure the Maven repository address and agconnect plugin for the HMS SDK.

  buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://developer.huawei.com/repo/' }
    }

    dependencies {
        /* 
          * <Other dependencies>
          */
        classpath 'com.huawei.agconnect:agcp:1.4.1.300'
    }
  }
- Go to **allprojects** then configure the Maven repository address for the HMS SDK.
  allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://developer.huawei.com/repo/' }
    }
  }

Step 9: Open the build.gradle file in the android/app directory.

  • Add apply plugin: 'com.huawei.agconnect' line after other apply entries.

    apply plugin: 'com.android.application'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    apply plugin: 'com.huawei.agconnect'
    
    • Set your package name in defaultConfig > applicationId and set minSdkVersion to 19 or higher. Package name must match with the package_name entry in agconnect-services.json file.
    defaultConfig {
        applicationId "<package_name>"
        minSdkVersion 17
        /*
        * <Other configurations>
        */
    }
    
    • Copy the signature file that generated in Generating a Signing Certificate to android/app directory.

    • Configure the signature in android according to the signature file information.

signingConfigs {
    config {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.config
    }
    release {
        signingConfig signingConfigs.config
    }
}

Step 10: On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies. For more details please refer the Using packages document.

      dependencies:
        huawei_location:
            # Replace {library path} with actual library path of Huawei Push Kit Location for Flutter.
            path: {library path}

-Step 11: Run following command to update package info.

[project_path]> flutter pub get

Step 12: Run following command to start the app.

[project_path]> flutter run

API Reference

Overview

ModuleDescription
FusedLocationProviderClientWith this module you can check the device location settings, get the last known location information once or continuously, set mock location and others.
ActivityIdentificationServiceIf 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.
GeofenceServiceIf 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.

FusedLocationProviderClient

Public Constructor Summary

ConstructorDescription
FusedLocationProviderClient()Default constructor.

Public Method Summary

MethodReturn TypeDescription
checkLocationSettings(LocationSettingsRequest locationSettingsRequest)Future<LocationSettingsStates>This API is used to check location settings of the device.
getLastLocation()Future<Location>This API is used to obtain the last requested available location. This API does not proactively request the location. Instead, it uses the location cached for the last request.
getLastLocationWithAddress(LocationRequest locationRequest)Future<HWLocation>This API is used to obtain the available location of the last request, including the detailed address information.
getLocationAvailability()Future<LocationAvailability>This API is used to check whether the location data is available.
setMockMode(bool mockMode)Future<void>This API is used to specify whether the location provider uses the location mock mode. If yes, the GPS or network location is not used and the location set through setMockLocation (Location) is directly returned.
setMockLocation(Location location)Future<void>This API is used to set the specific mock location. You must call the setMockMode(boolean) method and set the flag to true before calling this method.
requestLocationUpdates(LocationRequest locationRequest)Future<int>This API is used to continuously request location updates.
requestLocationUpdatesCb(LocationRequest locationRequest, LocationCallback locationCallback)Future<int>This API is used to request location updates using the callback.
requestLocationUpdatesExCb(LocationRequest locationRequest, LocationCallback locationCallback)Future<int>This API is an extended location information service API. It supports high-precision location and is compatible with common location APIs. If the device does not support high-precision location or the app does not request the high-precision location permission, this API returns common location information similar to that returned by the requestLocationUpdates API.
removeLocationUpdates(int requestCode)Future<void>This API is used to remove location updates from the specified requestCode.
removeLocationUpdatesCb(int callbackId)Future<void>This API is used to remove location updates of the specified callbackId.
onLocationDataFuture\Location>This API is used to listen location updates that comes from requestLocationUpdates API method.
getNavigationContextState(int type)Future<NavigationResult>Obtains the requested navigation type.

Public Constructors

FusedLocationProviderClient()

Constructor for FusedLocationProviderClient object.

Public Methods

Future<LocationSettingsStates> checkLocationSettings(LocationSettingsRequest locationSettingsRequest) async

Checks location settings of the device.

ParameterDescription
locationSettingsRequestLocation setting request object.
Return TypeDescription
Future<LocationSettingsStates>LocationSettingsStates object if the operation is successful; PlatformException otherwise.
Future<Location> getLastLocation() async

Obtains the available location of the last request. Instead of proactively requesting a location, this method uses the location cached during the last request.

The value null may be returned in the following scenarios:

  • The location function has never been used.
  • The location function is disabled.
  • The device is restored to factory settings.

If real-time location is required, you are advised to proactively call requestLocationUpdates instead of this method. To receive a location once only, you can set numUpdates in LocationRequest to 1.

Return TypeDescription
Future<Location>Location object if the operation is successful; PlatformException otherwise.
Future<HWLocation> getLastLocationWithAddress(LocationRequest locationRequest) async

Obtains the available location of the last request, including the detailed address information. If no location is available, null is returned.

ParameterDescription
locationRequestLocation request object.
Return TypeDescription
Future<HWLocation>HWLocation object if the operation is successful; PlatformException otherwise.
Future<LocationAvailability> getLocationAvailability() async

Checks whether the location data is available.

Return TypeDescription
Future<LocationAvailability>LocationAvailability object if the operation is successful; PlatformException otherwise.
Future<void> setMockMode(bool mockMode) async

Sets whether the location provider uses the mock mode. If yes, the GPS or network location is not used and the location set through setMockLocation is directly returned.

ParameterDescription
mockModeIndicates whether the location provider uses the mock mode. true: yes; false: no.
Return TypeDescription
Future<void>No return value if the operation is successful; PlatformException otherwise.
Future<void> setMockLocation(Location location) async

Sets whether the location provider uses the mock mode. If yes, the GPS or network location is not used and the location set through setMockLocation is directly returned.

ParameterDescription
locationMock location.
Return TypeDescription
Future<void>No return value if the operation is successful; PlatformException otherwise.
Future<int> requestLocationUpdates(LocationRequest locationRequest) async

Continuously requests location updates. You can call the onLocationData API method to listen for location updates.

ParameterDescription
locationRequestLocation update request.
Return TypeDescription
Future<int>Request code if the operation is successful; PlatformException otherwise. The request code can be used to call the removeLocationUpdates method.
Future<int> requestLocationUpdatesCb(LocationRequest locationRequest, LocationCallback locationCallback) async

Requests location updates using the callback.

ParameterDescription
locationRequestLocation update request.
locationCallbackLocation update callback.
Return TypeDescription
Future<int>Callback ID if the operation is successful; PlatformException otherwise. The callback ID can be used to call the removeLocationUpdatesCb method.
Future<int> requestLocationUpdatesExCb(LocationRequest locationRequest, LocationCallback locationCallback) async

Continuously requests location updates. This method is an extended location information service API. It supports high-precision location and is compatible with common location APIs. If the device does not support high-precision location or the app does not request the high-precision location, this method returns common location information similar to that returned by the requestLocationUpdatesCb method.

ParameterDescription
locationRequestLocation update request.
locationCallbackLocation update callback.
Return TypeDescription
Future<int>Callback ID if the operation is successful; PlatformException otherwise. The callback ID can be used to call the removeLocationUpdatesCb method.
Future<void> removeLocationUpdates(int requestCode) async

Removes location updates based on the specified request code.

ParameterDescription
requestCodeRequest code returned by the requestLocationUpdates method.
Return TypeDescription
Future<void>No return value if the operation is successful; PlatformException otherwise.
Future<void> removeLocationUpdatesCb(int callbackId) async

Removes location updates based on the specified callback ID.

ParameterDescription
callbackIdCallback ID returned by the requestLocationUpdatesCb or requestLocationUpdatesExCb method.
Return TypeDescription
Future<void>No return value if the operation is successful; PlatformException otherwise.
Stream<Location> onLocationData

Listens for location updates that come from the requestLocationUpdates method.

Return TypeDescription
Stream<Location>Stream of Location object. You can call the .listen() method to subscribe to this stream and listen for updates.
Future<NavigationResult> getNavigationContextState(int type) async

Removes location updates based on the specified callback ID.

ParameterDescription
typeRequested navigation type.
Return TypeDescription
Future<NavigationResult>NavigationResult object if the operation is successful; PlatformException otherwise.

Location

Public Properties

PropertiesTypeDescription
providerStringLocation provider, such as network location, GPS, Wi-Fi, and Bluetooth.
latitudedoubleLatitude of a location. If no latitude is available, 0.0 is returned.
longitudedoubleLongitude of a location. If no longitude is available, 0.0 is returned.
altitudedoubleAltitude of a location. If no altitude is available, 0.0 is returned.
speeddoubleSpeed of a device at the current location, in meters per second. If no speed is available, 0.0 is returned.
bearingdoubleBearing of a device at the current location, in degrees. If no bearing is available, 0.0 is returned.
horizontalAccuracyMetersdoubleHorizontal error of a location, in meters. If no horizontal error is available, 0.0 is returned.
verticalAccuracyMetersdoubleVertical error of a location, in meters. If no vertical error is available, 0.0 is returned.
speedAccuracyMetersPerSeconddoubleSpeed error of a device at the current location, in meters per second. If no speed error is available, 0.0 is returned.
bearingAccuracyDegreesdoubleBearing error of the current location, in degrees. If no bearing error is available, 0.0 is returned.
timeintCurrent timestamp, in milliseconds.
elapsedRealtimeNanosintTime elapsed since the system was started, in nanoseconds

Public Constructor Summary

ConstructorDescription
Location({String provider, double latitude, double longitude, double altitude, double speed, double bearing, double horizontalAccuracyMeters, double verticalAccuracyMeters, double speedAccuracyMetersPerSecond, double bearingAccuracyDegrees, int time, int elapsedRealtimeNanos})Default constructor.
Location.fromMap(Map<dynamic, dynamic> map)Creates a Location object from a map.
Location.fromJson(String source)Creates a Location object from a JSON string.

Public Constructors

Location({String provider, double latitude, double longitude, double altitude, double speed, double bearing, double horizontalAccuracyMeters, double verticalAccuracyMeters, double speedAccuracyMetersPerSecond, double bearingAccuracyDegrees, int time, int elapsedRealtimeNanos})

Constructor for Location object.

ParameterTypeDescription
providerStringLocation provider, such as network location, GPS, Wi-Fi, and Bluetooth.
latitudedoubleLatitude of a location. If no latitude is available, 0.0 is returned.
longitudedoubleLongitude of a location. If no longitude is available, 0.0 is returned.
altitudedoubleAltitude of a location. If no altitude is available, 0.0 is returned.
speeddoubleSpeed of a device at the current location, in meters per second. If no speed is available, 0.0 is returned.
bearingdoubleBearing of a device at the current location, in degrees. If no bearing is available, 0.0 is returned.
horizontalAccuracyMetersdoubleHorizontal error of a location, in meters. If no horizontal error is available, 0.0 is returned.
verticalAccuracyMetersdoubleVertical error of a location, in meters. If no vertical error is available, 0.0 is returned.
speedAccuracyMetersPerSeconddoubleSpeed error of a device at the current location, in meters per second. If no speed error is available, 0.0 is returned.
bearingAccuracyDegreesdoubleBearing error of the current location, in degrees. If no bearing error is available, 0.0 is returned.
timeintCurrent timestamp, in milliseconds.
elapsedRealtimeNanosintTime elapsed since the system was started, in nanoseconds
Location.fromMap(Map<dynamic, dynamic> map)

Creates a Location object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
Location.fromJson(String source)

Creates a Location object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

HWLocation

Public Properties

PropertiesTypeDescription
providerStringLocation provider, such as network location, GPS, Wi-Fi, and Bluetooth.
latitudedoubleLatitude of a location. If no latitude is available, 0.0 is returned.
longitudedoubleLongitude of a location. If no longitude is available, 0.0 is returned.
altitudedoubleAltitude of a location. If no altitude is available, 0.0 is returned.
speeddoubleSpeed of a device at the current location, in meters per second. If no speed is available, 0.0 is returned.
bearingdoubleBearing of a device at the current location, in degrees. If no bearing is available, 0.0 is returned.
horizontalAccuracyMetersdoubleHorizontal error of a location, in meters. If no horizontal error is available, 0.0 is returned.
verticalAccuracyMetersdoubleVertical error of a location, in meters. If no vertical error is available, 0.0 is returned.
speedAccuracyMetersPerSeconddoubleSpeed error of a device at the current location, in meters per second. If no speed error is available, 0.0 is returned.
bearingAccuracyDegreesdoubleBearing error of the current location, in degrees. If no bearing error is available, 0.0 is returned.
timeintCurrent timestamp, in milliseconds.
elapsedRealtimeNanosintTime elapsed since the system was started, in nanoseconds
countryCodeStringCountry code. The value is a two-letter code complying with the ISO 3166-1 standard.
countryNameStringCountry name.
stateStringAdministrative region.
cityStringCity of the current location.
countyStringCounty of the current location.
streetStringStreet of the current location.
featureNameStringLandmark building at the current location.
postalCodeStringPostal code of the current location.
phoneStringPhone number of the landmark building (such as a store or company) at the current location.
urlStringWebsite of the landmark building (such as a store or company) at the current location.
extraInfoMap<String, dynamic>Additional information, which is a key-value pair.

Public Constructor Summary

ConstructorDescription
HWLocation({String provider, double latitude, double longitude, double altitude, double speed, double bearing, double horizontalAccuracyMeters, double verticalAccuracyMeters, double speedAccuracyMetersPerSecond, double bearingAccuracyDegrees, int time, int elapsedRealtimeNanos, String countryCode, String countryName, String state, String city, String county, String street, String featureName, String postalCode, String phone, String url, Map<String, dynamic> extraInfo})Default constructor.
HWLocation.fromMap(Map<dynamic, dynamic> map)Creates a HWLocation object from a map.
HWLocation.fromJson(String source)Creates a HWLocation object from a JSON string.

Public Constructors

HwLocation({String provider, double latitude, double longitude, double altitude, double speed, double bearing, double horizontalAccuracyMeters, double verticalAccuracyMeters, double speedAccuracyMetersPerSecond, double bearingAccuracyDegrees, int time, int elapsedRealtimeNanos})

Constructor for Location object.

ParameterTypeDescription
providerStringLocation provider, such as network location, GPS, Wi-Fi, and Bluetooth.
latitudedoubleLatitude of a location. If no latitude is available, 0.0 is returned.
longitudedoubleLongitude of a location. If no longitude is available, 0.0 is returned.
altitudedoubleAltitude of a location. If no altitude is available, 0.0 is returned.
speeddoubleSpeed of a device at the current location, in meters per second. If no speed is available, 0.0 is returned.
bearingdoubleBearing of a device at the current location, in degrees. If no bearing is available, 0.0 is returned.
horizontalAccuracyMetersdoubleHorizontal error of a location, in meters. If no horizontal error is available, 0.0 is returned.
verticalAccuracyMetersdoubleVertical error of a location, in meters. If no vertical error is available, 0.0 is returned.
speedAccuracyMetersPerSeconddoubleSpeed error of a device at the current location, in meters per second. If no speed error is available, 0.0 is returned.
bearingAccuracyDegreesdoubleBearing error of the current location, in degrees. If no bearing error is available, 0.0 is returned.
timeintCurrent timestamp, in milliseconds.
elapsedRealtimeNanosintTime elapsed since the system was started, in nanoseconds
countryCodeStringCountry code. The value is a two-letter code complying with the ISO 3166-1 standard.
countryNameStringCountry name.
stateStringAdministrative region.
cityStringCity of the current location.
countyStringCounty of the current location.
streetStringStreet of the current location.
featureNameStringLandmark building at the current location.
postalCodeStringPostal code of the current location.
phoneStringPhone number of the landmark building (such as a store or company) at the current location.
urlStringWebsite of the landmark building (such as a store or company) at the current location.
extraInfoMap<String, dynamic>Additional information, which is a key-value pair.
HWLocation.fromMap(Map<dynamic, dynamic> map)

Creates a HWLocation object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
HWLocation.fromJson(String source)

Creates a HWLocation object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

LocationAvailability

Device location availability.

Public Properties

PropertiesTypeDescription
cellStatusintAvailability status code of cell location. Currently not provided. Value is always 0.
wifiStatusintAvailability status code of wifi location. Currently not provided. Value is always 0.
elapsedRealtimeNsintTime elapsed since the system was started, in nanoseconds. Currently not provided. Value is always 0.
locationStatusintLocation status code. If the value of smaller than 1000, then device location is available.

NOTE:

Currently, cellStatus, wifiStatus and elapsedRealtimeNs are not provided and have a fixed value of 0.

Public Constructor Summary

ConstructorDescription
LocationAvailability({int cellStatus, int wifiStatus, int elapsedRealtimeNs, int locationStatus})Default constructor.
LocationAvailability.fromMap(Map<dynamic, dynamic> map)Creates a LocationAvailability object from a map.
LocationAvailability.fromJson(String source)Creates a LocationAvailability object from a JSON string.

Public Method Summary

MethodsReturn TypeDescription
isLocationAvailableboolIndicates if the location is available or not.

Public Constructors

LocationAvailability({int cellStatus, int wifiStatus, int elapsedRealtimeNs, int locationStatus})

Constructor for LocationAvailability object.

ParameterTypeDescription
cellStatusintAvailability status code of cell location. Currently not provided. Value is always 0.
wifiStatusintAvailability status code of wifi location. Currently not provided. Value is always 0.
elapsedRealtimeNsintTime elapsed since the system was started, in nanoseconds. Currently not provided. Value is always 0.
locationStatusintLocation status code. If the value of smaller than 1000, then device location is available.
LocationAvailability.fromMap(Map<dynamic, dynamic> map)

Creates a LocationAvailability object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
LocationAvailability.fromJson(String source)

Creates a LocationAvailability object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

Public Methods

bool isLocationAvaible

Checks whether the device location is available. If yes, the value true is returned. A number of causes may result in failure to determine the location, such as that the location function is disabled or sensor data cannot be obtained from the device.

Return TypeDescription
StringJSON string as a source.

LocationCallback

Public Properties

PropertiesTypeDescription
onLocationAvailabilityvoid Function(LocationAvailability locationAvailability)Callback function to listen location availability changes.
onLocationResultvoid Function(LocationResult locationResult)Callback function to listen location updates.

Public Constructor Summary

ConstructorDescription
LocationCallback({void Function onLocationResult, void Function onLocationAvailability})Default constructor.

Public Constructors

LocationCallback({void Function onLocationResult, void Function onLocationAvailability})

Constructor for LocationCallback object.

ParameterTypeDescription
onLocationResultvoid FunctionCallback function to trigger when the device location is available.
onLocationAvailabilityvoid FunctionCallback function to trigger when the device location availability changes.

LocationRequest

Location request class.

Public Properties

PropertiesTypeDescription
priorityintRequest priority. The default value is 100.
intervalintRequest interval, in milliseconds. The default value is 3600000.
fastestIntervalintShortest 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.
expirationTimeintRequest expiration time, in milliseconds.
numUpdatesintNumber of requested location updates.
smallestDisplacementdoubleMinimum displacement between location updates, in meters.
maxWaitTimeintMaximum waiting timeIndicates whether to return the address information. The default value is false.
needAddressboolIndicates 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.

Public Constants

ConstantsTypeValueDescription
PRIORITY_HIGH_ACCURACYint100Used to request the most accurate location.
PRIORITY_BALANCED_POWER_ACCURACYint102Used to request the block-level location.
PRIORITY_LOW_POWERint104Used to request the city-level location.
PRIORITY_NO_POWERint105Used to request the location with the optimal accuracy without additional power consumption.
PRIORITY_HD_ACCURACYint200Used to request the high-precision location information. Currently, this parameter is available only for the requestLocationUpdatesExCb API.

Public Constructor Summary

ConstructorDescription
LocationRequest()Default constructor.
LocationRequest.fromMap(Map<dynamic, dynamic> map)Creates a Location object from a map.
LocationRequest.fromJson(String source)Creates a Location object from a JSON string.

Public Method Summary

Return TypeMethodDescription
boolisFastestIntervalExplicitlySetIndicates whether the fastest interval explicitly set or default value is being used.

Public Constructors

LocationRequest()

Constructor for Location object.

LocationRequest.fromMap(Map<dynamic, dynamic> map)

Creates a Location object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
LocationRequest.fromJson(String source)

Creates a Location object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

Public Methods

bool isFastestIntervalExplicitlySet

Checks whether the shortest interval is used.

MethodsReturn TypeDescription
isFastestIntervalExplicitlySetboolIndicates whether the fastest interval explicitly set or default value is being used.

LocationResult

Location data information class.

Public Properties

PropertiesTypeDescription
locationsList<Location>Available locations, which are ordered from oldest to newest.
hwLocationsList<HWLocation>List of available locations sorted from oldest to newest, including the detailed address information.
lastLocationLocationAvailable location of the last request.
lastHWLocationHWLocationAvailable location of the last request, including the detailed address information.

Public Constructor Summary

ConstructorDescription
LocationResult({List locations, List hwLocations, Location lastLocation, HWLocation lastHWLocation})Default constructor.
LocationResult.fromMap(Map<dynamic, dynamic> map)Creates a Location object from a map.
LocationResult.fromJson(String source)Creates a Location object from a JSON string.

Public Constructors

LocationResult({List locations, List hwLocations, Location lastLocation, HWLocation lastHWLocation})

Constructor for LocationResult object.

ParameterTypeDescription
locationsList<Location>Available locations, which are sorted from oldest to newest.
hwLocationsList<HWLocation>List of available locations sorted from oldest to newest, including the detailed address.
lastLocationLocationAvailable location of the last request.
lastHWLocationHWLocationAvailable location of the last request, including the detailed address.
LocationResult.fromMap(Map<dynamic, dynamic> map)

Creates a LocationResult object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
LocationResult.fromJson(String source)

Creates a LocationResult object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

LocationSettingsRequest

Class for specifying the location service types and checking the location settings to obtain optimal functionality of all requested services.

Public Properties

PropertiesTypeDescription
requestsList<LocationRequest>Collection of LocationRequest object.
alwaysShowboolIndicates whether BLE scanning needs to be enabled. The options are true (yes) and false (no).
needBleboolIndicates whether a location is required for the app to continue. The options are true (yes) and false (no).

Public Constructor Summary

ConstructorDescription
LocationSettingsRequest({List<LocationRequest> requests, bool alwaysShow, bool needBle})Default constructor.
LocationSettingsRequest.fromMap(Map<dynamic, dynamic> map)Creates a LocationSettingsRequest object from a map.
LocationSettingsRequest.fromJson(String source)Creates a LocationSettingsRequest object from a JSON string.

Public Constructors

LocationSettingsRequest({List<LocationRequest> requests, bool alwaysShow, bool needBle})

Constructor for LocationSettingsRequest object.

ParameterTypeDescription
requestsList<LocationRequest>Collection of LocationRequest objects.
alwaysShowboolIndicates whether BLE scanning needs to be enabled. The options are true (yes) and false (no).
needBleboolIndicates whether a location is required for the app to continue. The options are true (yes) and false (no).
LocationSettingsRequest.fromMap(Map<dynamic, dynamic> map)

Creates a LocationSettingsRequest object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
LocationSettingsRequest.fromJson(String source)

Creates a LocationSettingsRequest object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

LocationSettingsStates

Current location-related setting status.

Public Properties

PropertiesTypeDescription
blePresentboolIndicates whether the BLE exists on the device.
bleUsableboolIndicates whether the BLE is enabled and can be used by the app.
gpsPresentboolIndicates whether the GPS provider exists on the device.
gpsUsableboolIndicates whether the GPS provider is enabled and can be used by the app.
locationPresentboolIndicates whether the location provider exists on the device.
locationUsableboolIndicates whether the location provider is enabled and can be used by the app.
networkLocationPresentboolIndicates whether the network location provider exists on the device.
networkLocationUsableboolIndicates whether the network location provider is enabled and can be used by the app.

Public Constructor Summary

ConstructorDescription
LocationSettingsStates({bool blePresent, bool bleUsable, bool gpsPresent, bool gpsUsable, bool locationPresent, bool locationUsable, bool networkLocationPresent, bool networkLocationUsable})Default constructor.
LocationSettingsStates.fromMap(Map<dynamic, dynamic> map)Creates a LocationSettingsStates object from a map.
LocationSettingsStates.fromJson(String source)Creates a LocationSettingsStates object from a JSON string.

Public Constructors

LocationSettingsStates({bool blePresent, bool bleUsable, bool gpsPresent, bool gpsUsable, bool locationPresent, bool locationUsable, bool networkLocationPresent, bool networkLocationUsable})

Constructor for LocationSettingsStates object.

ParameterTypeDescription
blePresentboolIndicates whether the BLE exists on the device.
bleUsableboolIndicates whether the BLE is enabled and can be used by the app.
gpsPresentboolIndicates whether the GPS provider exists on the device.
gpsUsableboolIndicates whether the GPS provider is enabled and can be used by the app.
locationPresentboolIndicates whether the location provider exists on the device.
locationUsableboolIndicates whether the location provider is enabled and can be used by the app.
networkLocationPresentboolIndicates whether the network location provider exists on the device.
networkLocationUsableboolIndicates whether the network location provider is enabled and can be used by the app.
LocationSettingsStates.fromMap(Map<dynamic, dynamic> map)

Creates a Location object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
LocationSettingsStates.fromJson(String source)

Creates a Location object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

Public Properties

MethodsReturn TypeDescription
possibilityintObtains the confidence of the status information. The value ranges from 0 to 100. A larger value indicates more reliable result authenticity.
stateintStatus information.If the navigation type is IS_SUPPORT_EX, the return values are described as follows: 11: The user device supports high-precision location.12: The user device does not support high-precision location.

Public Constructor Summary

ConstructorDescription
NavigationResult({state, possibility})Default constructor.
NavigationResult.fromMap(Map<dynamic, dynamic> map)Creates a NavigationResult object from a map.
NavigationResult.fromJson(String source)Creates a NavigationResult object from a JSON string.

Public Constructors

Constructor for NavigationResult object.

ParameterReturn TypeDescription
possibilityintObtains the confidence of the status information. The value ranges from 0 to 100. A larger value indicates more reliable result authenticity.
stateintStatus information.If the navigation type is IS_SUPPORT_EX, the return values are described as follows: 11: The user device supports high-precision location.12: The user device does not support high-precision location.

Creates a NavigationResult object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.

Creates a NavigationResult object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

Public Properties

PropertiesTypeDescription
typeintRequested navigation type.

Public Constants

ConstantsTypeValueDescription
IS_SUPPORT_EXint2Used to check whether the device supports high-precision location.

ActivityIdentificationService

Interaction access point of activity identification.

Public Constructor Summary

ConstructorDescription
ActivityIdentificationService()Default constructor.

Public Method Summary

Return TypeMethodDescription
Future<int>createActivityIdentificationUpdates(int detectionIntervalMillis)This API is used to register for activity identification updates.
Future<int>createActivityConversionUpdates(List<ActivityConversionInfo> activityConversions)This API is used to activity conversions (entering and exit), for example, detecting user status change from walking to bicycling.The Conversion API supports the following activity parameters.
Future<void>deleteActivityIdentificationUpdates(int requestCode)This API is used to remove all activity identification updates from the specified requestCode.
Future<void>deleteActivityConversionUpdates(int requestCode)This API is used to remove all activity conversion updates from the specified requestCode.
Stream<ActivityIdentificationResponse>onActivityIdentificationThis API is used to listen activity identification updates that comes from createActivityIdentificationUpdates API method.
Stream<ActivityConversionResponse>onActivityConversionThis API is used to listen activity conversion updates that comes from createActivityConversionUpdates API method.

Public Constructors

ActivityIdentificationService()

Constructor for ActivityIdentificationService object.

Public Methods

Future<int> createActivityIdentificationUpdates(int detectionIntervalMillis) async

Registers for activity identification updates.

ParameterDescription
detectionIntervalMillisInterval for activity identification updates, in milliseconds. A larger value will result in a lower activity identification frequency, while a smaller value will result in a higher activity identification frequency.
Return TypeDescription
Future<int>Request code if the operation is successful; PlatformException otherwise. The request code can be used to call the deleteActivityIdentificationUpdates method.
Future<int> createActivityConversionUpdates(List<ActivityConversionInfo> activityConversions) async

Registers for activity conversion updates (entering and exit), for example, detecting user status change from walking to bicycling.

ParameterDescription
activityConversionsActivity conversion list.
Return TypeDescription
Future<int>Request code if the operation is successful; PlatformException otherwise. The request code can be used to call the deleteActivityConversionUpdates method.
Future<void> deleteActivityIdentificationUpdates(int requestCode) async

Removes activity identification updates based on the specified request code.

ParameterDescription
requestCodeRequest code returned by the createActivityIdentificationUpdates method.
Return TypeDescription
Future<void>No return value if the operation is successful; PlatformException otherwise.
Future<void> deleteActivityConversionUpdates(int requestCode) async

Removes activity conversion updates based on the specified request code.

ParameterDescription
requestCodeRequest code returned by the createActivityConversionUpdates method.
Return TypeDescription
Future<void>No return value if the operation is successful; PlatformException otherwise.
Stream<ActivityIdentificationResponse> onActivityIdentification

Listens for activity identification updates that come from the createActivityIdentificationUpdates method.

Return TypeDescription
Stream<ActivityIdentificationResponse>Stream of ActivityIdentificationResponse object. You can call the .listen() method to subscribe to this stream and listen for updates.
Stream<ActivityConversionResponse> onActivityConversion

Listens for activity conversion updates that come from the createActivityConversionUpdates method.

Return TypeDescription
Stream<ActivityConversionResponse>Stream of ActivityConversionResponse object. You can call the .listen() method to subscribe to this stream and listen for updates.

ActivityConversionData

Activity conversion event.

Public Properties

PropertiesTypeDescription
activityTypeintActivity type of the conversion. The value is one of the activity types defined in ActivityIdentificationData.
conversionTypeintActivity conversion information. The options are ActivityConversionInfo.ENTER_ACTIVITY_CONVERSION and ActivityConversionInfo.EXIT_ACTIVITY_CONVERSION.
elapsedTimeFromRebootintElapsed real time (in milliseconds) of this conversion since boot.

Public Constructor Summary

ConstructorDescription
ActivityConversionData({int activityType, int conversionType, int elapsedTimeFromReboot})Default constructor.
ActivityConversionData.fromMap(Map<dynamic, dynamic> map)Creates a ActivityConversionData object from a map.
ActivityConversionData.fromJson(String source)Creates a ActivityConversionData object from a JSON string.

Public Constructors

ActivityConversionData({int activityType, int conversionType, int elapsedTimeFromReboot})

Constructor for ActivityConversionData object.

ParameterTypeDescription
activityTypeintActivity type of the conversion. The value is one of the activity types defined in ActivityIdentificationData.
conversionTypeintActivity conversion information. The options are ActivityConversionInfo.ENTER_ACTIVITY_CONVERSION and ActivityConversionInfo.EXIT_ACTIVITY_CONVERSION.
elapsedTimeFromRebootintElapsed real time (in milliseconds) of this conversion since boot.
ActivityConversionData.fromMap(Map<dynamic, dynamic> map)

Creates a ActivityConversionData object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
ActivityConversionData.fromJson(String source)

Creates a ActivityConversionData object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

ActivityConversionInfo

Activity conversion information.

Public Properties

PropertiesTypeDescription
activityTypeintActivity type of the conversion. The value is one of the activity types defined in ActivityIdentificationData.
conversionTypeintActivity conversion information. The options are ActivityConversionInfo.ENTER_ACTIVITY_CONVERSION and ActivityConversionInfo.EXIT_ACTIVITY_CONVERSION.

Public Constants

ConstantsTypeValueDescription
ENTER_ACTIVITY_CONVERSIONint0A user enters the given activity.
EXIT_ACTIVITY_CONVERSIONint1A user exits the given activity.

Public Constructor Summary

ConstructorDescription
ActivityConversionInfo({int activityType, int conversionType})Default constructor.
ActivityConversionInfo.fromMap(Map<dynamic, dynamic> map)Creates a ActivityConversionInfo object from a map.
ActivityConversionInfo.fromJson(String source)Creates a ActivityConversionInfo object from a JSON string.

Public Constructors

ActivityConversionInfo({int activityType, int conversionType})

Constructor for ActivityConversionInfo object.

PropertiesTypeDescription
activityTypeintActivity type of the conversion. The value is one of the activity types defined in ActivityIdentificationData.
conversionTypeintActivity conversion information. The options are ActivityConversionInfo.ENTER_ACTIVITY_CONVERSION and ActivityConversionInfo.EXIT_ACTIVITY_CONVERSION.
ActivityConversionInfo.fromMap(Map<dynamic, dynamic> map)

Creates a ActivityConversionInfo object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
ActivityConversionInfo.fromJson(String source)

Creates a ActivityConversionInfo object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

ActivityConversionResponse

Activity conversion result.

Public Properties

PropertiesTypeDescription
activityConversionDatasList<ActivityConversionData>All activity conversion events in the result. The obtained activity events are sorted by time in ascending order.

Public Constructor Summary

ConstructorDescription
ActivityConversionResponse({List<ActivityConversionData> activityConversionDatas})Default constructor.
ActivityConversionResponse.fromMap(Map<dynamic, dynamic> map)Creates a ActivityConversionResponse object from a map.
ActivityConversionResponse.fromJson(String source)Creates a ActivityConversionResponse object from a JSON string.

Public Constructors

ActivityConversionResponse({List<ActivityConversionData> activityConversionDatas})

Constructor for ActivityConversionResponse object.

ParameterTypeDescription
activityConversionDatasList<ActivityConversionData>All activity conversion events in the result. The obtained activity events are sorted by time in ascending order.
ActivityConversionResponse.fromMap(Map<dynamic, dynamic> map)

Creates a ActivityConversionResponse object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
ActivityConversionResponse.fromJson(String source)

Creates a ActivityConversionResponse object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

ActivityIdentificationData

Class for detecting the activity.

Public Properties

PropertiesTypeDescription
identificationActivityintType of the detected activity.
possibilityintThe confidence for the user to execute the activity. The confidence ranges from 0 to 100. A larger value indicates more reliable activity authenticity.

Public Constants

ConstantsTypeValueDescription
VEHICLEint100The device is in a vehicle, such as a car.
BIKEint101The device is on a bicycle.
FOOTint102The device user is walking or running.
STILLint103The device is still.
OTHERSint104The current activity cannot be detected.
TILTINGint105The device has an obvious tilt change.
WALKINGint107The user of the device is walking,it is a sub-activity of FOOT.
RUNNINGint108The user of the device is running,it is a sub-activity of FOOT.

Public Constructor Summary

ConstructorDescription
ActivityIdentificationData({int identificationActivity, int possibility})Default constructor.
ActivityIdentificationData.fromMap(Map<dynamic, dynamic> map)Creates a ActivityIdentificationData object from a map.
ActivityIdentificationData.fromJson(String source)Creates a ActivityIdentificationData object from a JSON string.

Public Method Summary

MethodsReturn TypeDescription
static isValidType(int type)boolChecks that given activity type is one of the valid constants.

Public Constructors

ActivityIdentificationData({int identificationActivity, int possibility})

Constructor for ActivityIdentificationData object.

ParameterTypeDescription
identificationActivityintType of the detected activity.
possibilityintThe confidence for the user to execute the activity. The confidence ranges from 0 to 100. A larger value indicates more reliable activity authenticity.
ActivityIdentificationData.fromMap(Map<dynamic, dynamic> map)

Creates a ActivityIdentificationData object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
ActivityIdentificationData.fromJson(String source)

Creates a ActivityIdentificationData object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

Public Methods

bool isValidType

Checks whether the specified activity type is a valid constant.

Return TypeDescription
booltrue if the specified activity type is a valid constant; false otherwise.

ActivityIdentificationResponse

Activity identification result.

Public Properties

PropertiesTypeDescription
timeintTime of this identification, which is in milliseconds since January 1, 1970.
elapsedTimeFromRebootintElapsed real time (in milliseconds) of this identification since boot.
activityIdentificationDatasList<ActivityIdentificationData>List of activitiy identification list. The activity identifications are sorted by most probable activity first.

Public Constructor Summary

ConstructorDescription
ActivityIdentificationResponse({int time, int elapsedTimeFromReboot, List<ActivityIdentificationData> activityIdentificationDatas})Default constructor.
ActivityIdentificationResponse.fromMap(Map<dynamic, dynamic> map)Creates a ActivityIdentificationResponse object from a map.
ActivityIdentificationResponse.fromJson(String source)Creates a ActivityIdentificationResponse object from a JSON string.

Public Method Summary

MethodsReturn TypeDescription
mostActivityIdentificationActivityIdentificationDataThis API is used to obtain the most probable activity identification of the user.
getActivityPossibility(int activityType)intThis API is used to obtain the confidence of an activity type.

Public Constructors

ActivityIdentificationResponse({int time, int elapsedTimeFromReboot, List<ActivityIdentificationData> activityIdentificationDatas})

Constructor for ActivityIdentificationResponse object.

ParameterTypeDescription
timeintTime of this identification, which is in milliseconds since January 1, 1970.
elapsedTimeFromRebootintElapsed real time (in milliseconds) of this identification since boot.
activityIdentificationDatasList<ActivityIdentificationData>List of activitiy identification list. The activity identifications are sorted by most probable activity first.
ActivityIdentificationResponse.fromMap(Map<dynamic, dynamic> map)

Creates a ActivityIdentificationResponse object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
ActivityIdentificationResponse.fromJson(String source)

Creates a Location object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

Public Methods

ActivityIdentificationData mostActivityIdentification

Obtains the most possible activity of a user.

Return TypeDescription
ActivityIdentificationDataIdentified activity.
int getActivityPossibility

Obtains the confidence of an activity type.

ParameterDescription
activityTypeActivity type.
Return TypeDescription
intConfidence of the activity type.

Geofence Service

Interaction access point of geofence.

Public Constructor Summary

ConstructorDescription
GeofenceService()Default constructor.

Public Method Summary

Return TypeMethodDescription
Future<int>createGeofenceList(GeofenceRequest geofenceRequest)This API is used to add geofences. When a geofence is triggered, a notification can be listened through onGeofenceData API method.
Future<void>deleteGeofenceList(int requestCode)This API is used to remove geofences associated with a requestCode.
Future<void>deleteGeofenceListWithIds(List<String> geofenceIds)This API is used to remove geofences by their unique IDs.
Stream<GeofenceData>onGeofenceDataThis API is used to listen geofence updates that comes from createGeofenceList API method.

Public Constructors

GeofenceService()

Constructor for GeofenceService object.

Public Methods

Future<int> createGeofenceList(GeofenceRequest geofenceRequest) async

Adds geofences. When a geofence is triggered, the onGeofenceData method can listen for a notification.

ParameterDescription
geofenceRequestGeofence request object.
Return TypeDescription
Future<int>Request code if the operation is successful; PlatformException otherwise. The request code can be used to call the deleteGeofenceList method.
Future<void> deleteGeofenceList(int requestCode) async

Removes geofences associated with a request code.

ParameterDescription
requestCodeRequest code returned by the createGeofenceList method.
Return TypeDescription
Future<void>No return value if the operation is successful; PlatformException otherwise.
Future<void> deleteGeofenceListWithIds(List<String> geofenceIds) async

Removes geofences by their unique IDs.

ParameterDescription
geofenceIdsUnique IDs of geofences to be removed.
Return TypeDescription
Future<void>No return value if the operation is successful; PlatformException otherwise.
Stream<GeofenceData> onGeofenceData

Listens for geofence updates that come from the createGeofenceList method.

ParameterDescription
geofenceIdsUnique IDs of geofences to be removed.
Return TypeDescription
Stream<GeofenceData>Stream of GeofenceData object. You can call the .listen() method to subscribe to this stream and listen for updates.

Geofence

Class that contains information about geofences.

Public Properties

PropertiesTypeDescription
uniqueIdStringUnique ID. If the unique ID already exists, the new geofence will overwrite the old one.
conversionsintGeofence conversions. The bitwise-OR operation is supported.
validDurationintGeofence timeout interval, in milliseconds. The geofence will be automatically deleted after this amount of time.
latitudedoubleLatitude. The value range is -90,90.
longitudedoubleLongitude. The value range is -180,180.
radiusdoubleRadius, in meters.
notificationIntervalintNotification 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.
dwellDelayTimeintLingering duration for converting a geofence event, in milliseconds. A geofence event is converted when a user lingers in a geofence for this amount of time.

Public Constants

ConstantsTypeValueDescription
ENTER_GEOFENCE_CONVERSIONint1A user enters the geofence.
EXIT_GEOFENCE_CONVERSIONint2A user exits the geofence.
DWELL_GEOFENCE_CONVERSIONint4A user lingers in the geofence.
GEOFENCE_NEVER_EXPIREint-1No timeout interval is configured for the geofence.

Public Constructor Summary

ConstructorDescription
Geofence({String uniqueId, int conversions, int validDuration, double latitude, double longitude, double radius, int notificationInterval, int dwellDelayTime})Default constructor.
Geofence.fromMap(Map<dynamic, dynamic> map)Creates a Geofence object from a map.
Geofence.fromJson(String source)Creates a Geofence object from a JSON string.

Public Constructors

Geofence({String uniqueId, int conversions, int validDuration, double latitude, double longitude, double radius, int notificationInterval, int dwellDelayTime})

Constructor for Geofence object.

ParameterTypeDescription
uniqueIdStringUnique ID. If the unique ID already exists, the new geofence will overwrite the old one.
conversionsintGeofence conversions. The bitwise-OR operation is supported.
validDurationintGeofence timeout interval, in milliseconds. The geofence will be automatically deleted after this amount of time.
latitudedoubleLatitude. The value range is -90,90.
longitudedoubleLongitude. The value range is -180,180.
radiusdoubleRadius, in meters.
notificationIntervalintNotification 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.
dwellDelayTimeintLingering duration for converting a geofence event, in milliseconds. A geofence event is converted when a user lingers in a geofence for this amount of time.
Geofence.fromMap(Map<dynamic, dynamic> map)

Creates a Geofence object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
Geofence.fromJson(String source)

Creates a Geofence object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

GeofenceData

Geofence event.

Public Properties

PropertiesTypeDescription
errorCodeintError code.
conversionintGeofence convert type.
convertingGeofenceIdListList<String>List of converted geofence unique IDs.
convertingLocationLocationThe location when a geofence is converted.

Public Constructor Summary

ConstructorDescription
GeofenceData({int errorCode, int conversion, List convertingGeofenceIdList, Location convertingLocation})Default constructor.
GeofenceData.fromMap(Map<dynamic, dynamic> map)Creates a GeofenceData object from a map.
GeofenceData.fromJson(String source)Creates a GeofenceData object from a JSON string.

Public Constructors

GeofenceData({int errorCode, int conversion, List convertingGeofenceIdList, Location convertingLocation})

Constructor for GeofenceData object.

PropertiesTypeDescription
errorCodeintError code.
conversionintGeofence convert type.
convertingGeofenceIdListList<String>List of converted geofence unique IDs.
convertingLocationLocationThe location when a geofence is converted.
GeofenceData.fromMap(Map<dynamic, dynamic> map)

Creates a GeofenceData object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
GeofenceData.fromJson(String source)

Creates a GeofenceData object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

GeofenceRequest

Geofence request class.

Public Properties

PropertiesTypeDescription
geofenceListList<Geofence>List of geofences to be monitored.
initConversionsintInitial conversion type. This parameter is invalid if it is set to 0. The default value is GeofenceRequest.ENTER_INIT_CONVERSION | GeofenceRequest.DWELL_INIT_CONVERSION.
coordinateTypeintCoordinate type of geofences. Defaults to GeofenceRequest.COORDINATE_TYPE_WGS_84.

Public Constants

ConstantsTypeValueDescription
ENTER_INIT_CONVERSIONint1ENTER_INIT_CONVERSION is converted immediately when a request is initiated to add the geofence where a user device has already entered.
EXIT_INIT_CONVERSIONint2EXIT_INIT_CONVERSION is converted immediately when a request is initiated to add the geofence where a user device has already exit.
DWELL_INIT_CONVERSIONint4DWELL_INIT_CONVERSION is converted immediately when a request is initiated to add the geofence where a user device has already entered and stayed for the specified duration.
COORDINATE_TYPE_WGS_84int1WGS_84 coordinate system.
COORDINATE_TYPE_GCJ_02int0GCJ-02 coordinate system.

Public Constructor Summary

ConstructorDescription
GeofenceRequest({List<Geofence> geofenceList, int initConversions, int coordinateType})Default constructor.
GeofenceRequest.fromMap(Map<dynamic, dynamic> map)Creates a GeofenceRequest object from a map.
GeofenceRequest.fromJson(String source)Creates a GeofenceRequest object from a JSON string.

Public Constructors

GeofenceRequest({List<Geofence> geofenceList, int initConversions, int coordinateType})

Constructor for GeofenceRequest object.

PropertiesTypeDescription
geofenceListList<Geofence>List of geofences to be monitored.
initConversionsintInitial conversion type. This parameter is invalid if it is set to 0. The default value is GeofenceRequest.ENTER_INIT_CONVERSION | GeofenceRequest.DWELL_INIT_CONVERSION.
coordinateTypeintCoordinate type of geofences. Defaults to GeofenceRequest.COORDINATE_TYPE_WGS_84.
GeofenceRequest.fromMap(Map<dynamic, dynamic> map)

Creates a GeofenceRequest object from a map.

ParameterTypeDescription
mapMap<dynamic, dynamic>Map as a source.
GeofenceRequest.fromJson(String source)

Creates a GeofenceRequest object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

PermissionHandler

Checks or requests required permissions.

Public Constructor Summary

ConstructorDescription
PermissionHandler()Default constructor.

Public Method Summary

Return TypeMethodDescription
Future<bool>hasLocationPermission()This API is used to check location permission is available or not.
Future<bool>hasBackgroundLocationPermission()This API is used to check background location permission is available or not.
Future<bool>hasActivityRecognitionPermission()This API is used to check activity permission is available or not.
Future<bool>requestLocationPermission()This API is used to request location permission. Returns true if permission is granted, else returns false.
Future<bool>requestBackgroundLocationPermission()This API is used to request background location permission. Returns true if permission is granted, else returns false.
Future<bool>requestActivityRecognitionPermission()This API is used to request activity recognition permission. Returns true if permission is granted, else returns false.

Public Constructors

PermissionHandler()

Constructor for PermissionHandler object.

Public Methods

Future<bool> hasLocationPermission() async

Checks whether the location permission is available.

Return TypeDescription
Future<bool>true or false if the operation is successful; PlatformException otherwise.
Future<bool> hasBackgroundLocationPermission() async

Checks whether the background location permission is available.

Return TypeDescription
Future<bool>true or false if the operation is successful; PlatformException otherwise.
Future<bool> hasActivityRecognitionPermission() async

Checks whether the activity permission is available.

Return TypeDescription
Future<bool>true or false if the operation is successful; PlatformException otherwise.
Future<bool> requestLocationPermission() async

Requests the location permission. The value true is returned if the permission is granted. Otherwise, false is returned.

Return TypeDescription
Future<bool>true or false if the operation is successful; PlatformException otherwise.
Future<bool> requestBackgroundLocationPermission() async

Requests the background location permission. The value true is returned if the permission is granted. Otherwise, false is returned

Return TypeDescription
Future<bool>true or false if the operation is successful; PlatformException otherwise.
Future<bool> requestActivityRecognitionPermission() async

Requests the activity permission. The value true is returned if the permission is granted. Otherwise, false is returned.

Return TypeDescription
Future<bool>true or false if the operation is successful; PlatformException otherwise.

HMSLogger

Public Method Summary

Return TypeMethodDescription
Future<bool>enableLogger()This method enables the HMSLogger capability which is used for sending usage analytics of Location SDK's methods to improve the service quality..
Future<bool>disableLogger()This method disables the HMSLogger capability which is used for sending usage analytics of Location SDK's methods to improve the service quality.

Public Methods

Future<bool> enableLogger() async

This method enables the HMSLogger capability which is used for sending usage analytics of Location SDK's methods to improve the service quality. HMSLogger is enabled by default, it can be disabled with the disableLogger method.

Return TypeDescription
Future<bool>Future result of an execution that returns no value.
Future<bool> disableLogger() async

This method disables the HMSLogger capability which is used for sending usage analytics of Location SDK's methods to improve the service quality.

Return TypeDescription
Future<bool>Future result of an execution that returns no value.

Configuration Description

Preparing for Release

Before building a release version of your app you may need to customize the proguard-rules.pro obfuscation configuration file to prevent the HMS Core SDK from being obfuscated. Add the configurations below to exclude the HMS Core SDK from obfuscation. For more information on this topic refer to this Android developer guide.

<flutter_project>/android/app/proguard-rules. pro

-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}

<flutter_project>/android/app/build.gradle

buildTypes {
    debug {
        signingConfig signingConfigs.config
    }
    release {
        
        // Enables code shrinking, obfuscation and optimization for release builds
        minifyEnabled true
        // Unused resources will be removed, resources defined in the res/raw/keep.xml will be kept.
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
	
	signingConfig signingConfigs.config
    }
}

Sample Project

This plugin includes a demo project in the example folder, there you can find more usage examples.

Questions or Issues

If you have questions about how to use HMS samples, try the following options:

  • Stack Overflow is the best place for any programming questions. Be sure to tag your question with huawei-mobile-services.
  • Github is the official repository for these plugins, You can open an issue or submit your ideas.
  • Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.
  • Huawei Developer Docs is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.

If you run into a bug in our samples, please submit an issue to the Github Repository.

Licensing and Terms

Huawei Location Kit Flutter Plugin uses the Apache 2.0 license.

Libraries

activity_conversion_data
activity_conversion_info
activity_conversion_response
activity_identification_data
activity_identification_response
activity_identification_service
fused_location_provider_client
geofence
geofence_data
geofence_request
geofence_service
hmslogger
hwlocation
location
location_availability
location_callback
location_request
location_result
location_settings_request
location_settings_states
permission_handler