We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesLocation KitFAQs

FAQs

Content overview
Expand

Need more help? Go to Stack Overflow.

Location SDK for Android

After integrating the Location SDK, my app called the API successfully but failed to obtain the location on phones or Huawei tablets. Why?

  1. Ensure that you have installed HMS Core (APK) 3.0.0.300 or later.
  2. Ensure that the location permission has been assigned to HMS Core (APK). To do so, go to Settings > Apps > Apps and find HMS Core. (The menu path may vary depending on the operating system version. If HMS Core is not found, tap the menu icon in the upper right corner of Apps, tap Show system processes, and search for HMS Core or HMS.) Then, tap the HMS Core or HMS icon, go to App info > Permissions > Location, and verify that the location permission is assigned to HMS Core. On a device running EMUI 10.0 or later, Location must be set to Always for HMS Core.
  3. Ensure that Location is enabled for the app to be tested.
  4. Ensure that Location is enabled on the notification panel.
  5. Verify that the GNSS or network signal is strong. In regions where the GNSS or network signal is weak, the location may not be obtained.
  6. Verify that a SIM card is inserted into the device and works properly so that Location Kit can provide more precise locations.

What will happen if my app with Location SDK 6.0.0 or later integrated calls unsupported functions on non-Huawei Android phones?

The error code NOT_YET_SUPPORTED will be returned. On some phones, the following error logs may be recorded but normal functions are not affected:

Collapse
Word wrap
Dark theme
Copy code
  1. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: FATAL EXCEPTION: Location_Location_DispatchTaskManager_14'
  2. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: Process: com.huawei.locationsample6, PID: 30443'
  3. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: com.huawei.location.router.dispatch.DispatchException: api interface not register'
  4. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat com.huawei.location.router.dispatch.DispatchThreadPoolExecutor.processRequest(Unknown Source:90)'
  5. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat com.huawei.location.router.dispatch.DispatchThreadPoolExecutor.beforeExecute(Unknown Source:10)'
  6. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1164)'
  7. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)'
  8. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat java.lang.Thread.run(Thread.java:923)'
  9. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: FATAL EXCEPTION: Location_Location_DispatchTaskManager_14'
  10. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: Process: com.huawei.locationsample6, PID: 30443'
  11. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: com.huawei.location.router.dispatch.DispatchException: api interface not register'
  12. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat com.huawei.location.router.dispatch.DispatchThreadPoolExecutor.processRequest(Unknown Source:90)'
  13. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat com.huawei.location.router.dispatch.DispatchThreadPoolExecutor.beforeExecute(Unknown Source:10)'
  14. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1164)'
  15. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)'
  16. b'08-09 21:23:47.202 30443 18338 E AndroidRuntime: \tat java.lang.Thread.run(Thread.java:923)'

My app calls relevant APIs of the Location SDK successfully on a non-Huawei Android phone. However, the obtained location information does not include specific address information, such as the city. Why?

On non-Huawei Android phones, the Location SDK cannot return the specific address information of the current location, such as the city, district or county, and street.

A user had installed the latest HMS Core (APK) on their phone running Android 11, but they were still asked to update the APK. How should I resolve this issue?

In Android 11, the way for an app to query other apps on the user device and interact with them has been changed. If targetSdkVersion is 30 or later for your app and the Location SDK integrated into your app is earlier than 6.2.0.300, your app will be unable to access HMS Core (APK) and will continuously ask users to update the APK.

You can solve the issue using either of the following methods:

  • Method 1:

    Update the Location SDK to the latest version. For details about the latest version, please refer to Version Change History.

  • Method 2:

    If the SDK is not updated, add a <queries> element in the manifest element in AndroidManifest.xml.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. <manifest ...>
    2. ...
    3. <queries>
    4. <intent>
    5. <action android:name="com.huawei.hms.core.aidlservice" />
    6. </intent>
    7. </queries>
    8. ...
    9. </manifest>
    NOTE

    The <queries> element requires the following:

    • Your Android Studio version is 3.3 or later.
    • Your Android Gradle plugin version is 3.3.3, 3.4.3, 3.5.4, 3.6.4, 4.0.1, 4.1.0, or later.

When PRIORITY_NO_POWER is passed, the device location cannot be obtained. Why?

The PRIORITY_NO_POWER mode is used for passive location. It listens for the location of a native location request. If no app has initiated a native location request, this mode cannot obtain a location.

Why is result code -5 returned when Location Kit is used to obtain the user device location?

The possible cause is that the obfuscation configuration file is not configured to exclude the HMS Core SDK from being obfuscated. Perform operations in Configuring Obfuscation Scripts before building your APK.

Why cannot I obtain the device location using the getLastLocation method even though the device location settings are correct?

The getLastLocation method obtains the device location from the system cache. However, the cache may not contain the device location. If the obtained device location is null, the possible cause is that the system cache has been cleared. In this case, you need to call the requestLocationUpdates method to obtain the device location and update the cache, and then call the getLastLocation method to obtain the device location.

What are impacts of the mock mode on the normal location mode? How can I check whether the current location is a mock location?

After isMockMode is set to true using setMockMode(boolean isMockMode), Location Kit will return the location specified in setMockLocation(Location mockLocation) instead of using the GNSS or network location. Note that once the mock mode is enabled, the location function of all apps using Location Kit on the device will be affected. Therefore, when the mock mode is not required anymore, you are advised to set isMockMode to false using setMockMode(boolean isMockMode).

You can check whether the current location is a mock location based on the return value of mockLocation.getExtras().getBoolean("mockLocation"). If the return value is true, the current location is a mock location. If the return value is false, the current location is a real location.

How can I troubleshoot a fault based on the return value if my app fails to call an API?

If your app fails to call a Location Kit API, check the causes based on the return value using the following method: Obtain the Task object returned by the API, call addOnFailureListener(), override the onFailure(Exception e) method, and execute e.getMessage to print the error information. The error information contains the result code and result description. For details about the result codes, please refer to Result Codes.

How can I capture logs?

If your app does not receive the device location after calling a Location Kit API and the fault cannot be troubleshooted, you can capture run logs and go to Support > Technical Support > Customer Service to submit a ticket online. Huawei technical support will handle it in time.

The procedure for capturing logs is as follows:

  1. Run the following command to connect to the device:
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. adb logcat –v time > D:\hwlocation.log
  2. Reproduce the fault.
  3. Press Ctrl+C to complete log capture.

In addition, record the device model, EMUI version, HMS Core (APK) version, integrated SDK version, and fault reproduction procedure so that technical personnel can help you quickly troubleshoot the fault.

What are the earliest Android API level and OS versions for using Location Kit?

Expand

Earliest Android API Level

Earliest Android Version

Earliest EMUI Version

19

5.1

5.0

Why is the screen for applying for the location permission for HMS Core (APK) displayed when my app tries to obtain the device location?

For location purposes, your app needs to trigger the location service of HMS Core (APK). To ensure successful location, your app user needs to assign the location permission to HMS Core (APK), which is irrelevant to your app. For an Android Q device, your app user needs to assign HMS Core (APK) the permission to always obtain the device location in the background.

Why cannot I use the mock mode?

The setMockMode(boolean isMockMode) method can only be used on Huawei phones running EMUI 5.0 or later.

How can I enable the network location function on a Huawei phone without GMS?

Go to Settings > Location > LOCATION SERVICES > Network Location Services and toggle the Network Location Services switch on.

Can the navigation satellite location function be used on a Huawei phone without GMS and having the network location function disabled?

Yes. The navigation satellite location function is not affected when the phone is not connected to the network or the network location function is disabled.

Why is the location function unavailable when the location permission is set to Allow only while in use for HMS Core (APK)?

HMS Core (APK) runs in the background. The location permission must be set to Allow all the time for HMS Core (APK) so that the location function can be used properly.

When Location is set to Allow only while in use for my app, information "10803: PERMISSION_DENIED" is returned when my app initiates a location request in the background. Why?

You are advised to set Location to Allow all the time for your app. This can ensure that correct data can be continuously returned when your app initiates location requests in the background.

Why does indoor location take a long time?

In normal cases, the navigation satellite signal coverage is poor in indoor environments. Therefore, HMS Core (APK) uses the network location function which is slow compared with the satellite location function.

Should I use requestLocationUpdates or getLastLocation if I want to obtain the location once only?

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

Error code 10206 (GEOFENCE_SERVICE_SWITCH_OFF) is returned when I call the geofence API. How can I enable the geofence service?

Go to Settings > Privacy > Location Services > System services > Geofence Services and enable the geofence service.

What should I do if error information "IllegaArgumentException, Unsupported class file major version 59" is displayed after I add a dependency on Location SDK 6.12.0.300?

Add android.jetifier.blacklist=bcprov-jdk15on to the gradle.properties file.

Location Java SDK for HarmonyOS

What should I do if an error occurs during app installation?

Expand

Result Code

Solution

INSTALL_FAILED_APP_SOURCE_NOT_TRUSTED

  1. Obtain the device UDID.
    • To obtain the UDID of a smart watch, run the adb shell bm get -u command.
    • For other devices, please refer to Debugging a HarmonyOS App.
  2. Add the device to AppGallery Connect:
    • Sign in with your HUAWEI ID.
    • Go to Users and permissions and click Device management.
    • Enter the obtained UDID to add the device.

INSTALL_PARSE_FAILED_USESDK_ERROR

The value of apiVersion in config.json does not match the ROM version. Modify the value of apiVersion to make it match the ROM version.

INSTALL_PARSE_FAILED_PROFILE_MISSING_PROP

In config.json file, change the value of reqSdk to that of apiVersion. To do this, add apiVersion to the app field.

ERROR_GET_BUNDLE_INSTALLER_FAILED

The com.huawei.harmonyos.foundation process restarts. Run the adb shell ps -A | grep foundation command for multiple times to check whether the process restarts repeatedly, and analyze the process restart cause in detail. (Generally, the cause is so/jar mismatching, null pointer, or others.)

INSTALL_FAILED_RESTRICTED_PERMISSIONS_NOT_GRANTED

Restricted permissions are declared in the config.json file. However, the permissions are not assigned when the profile is applied for in the signature center.

Check whether restricted permissions are declared in the config.json file. If yes, add the permissions to restricted-permissions when applying for a debug profile or release the profile.

"permissions": {

"restricted-permissions": [

"ohos.permission.ANSWER_PHONE_CALLS", "# This field is optional. Restricted permissions are mainly sensitive permissions related to the phone numbers, SMS messages, and call records."

]}

INSTALL_FAILED_DEVICE_NOT_SUPPORT_ERROR

The possible causes are as follows:

  1. The deviceType parameter does not exist.
  2. The deviceType is typed as deviceTypes in configuration file.
  3. The value of deviceType in the configuration file does not include the type of this device.

The correct configuration (case sensitive) is as follows:

"module": {

"package": "com.huawei.hiworld.location",

"deviceType": [

"default",

"tv"

"car",

"wearable"

]

}

INSTALL_FAILED_INCOMPATIBLE_SIGNATURE

The signature of the new app package is different from that of the old app package. Manually uninstall the old app and then install the new one.

After integrating the Location SDK, my app called the API successfully but failed to obtain the location on Huawei smart watches. Why?

  1. Ensure that you have installed HMS Core (APK) 6.0.0.300 or later.
  2. Ensure that Location is set to Allow all the time for the app to be tested.
  3. Ensure that Location is enabled on the notification panel.
  4. Verify that the GNSS or network signal is strong. In regions where the GNSS or network signal is weak, the location may not be obtained. Verify that a SIM card is inserted into the device and works properly so that Location Kit can provide more precise locations.

Why cannot I obtain the device location using the getLastLocation method even though the device location settings are correct?

The getLastLocation method obtains the device location from the system cache. However, the cache may not contain the device location. If the obtained device location is null, the possible cause is that the system cache has been cleared. In this case, you need to call the requestLocationUpdates method to obtain the device location and update the cache, and then call the getLastLocation method to obtain the device location.

How can I troubleshoot a fault based on the return value if my app fails to call an API?

If your app fails to call a Location Kit API, check the causes based on the return value using the following method: Obtain the HarmonyTask object returned by the API, call addOnFailureListener(), override the onFailure(Exception exception) method, and execute e.getMessage() to print the error information. The error information contains the error code and error description. For details about the result codes, please refer to Result Codes.

When the location and background location permissions are set to Allow only while in use for my app, error "10803: PERMISSION_DENIED" is returned when my app initiates location requests. Why?

You are advised to set the background location permission to Allow all the time for your app. This can ensure that correct data can be continuously returned when your app initiates location requests in the background.

Location SDK for iOS

What are the location methods of the Location SDK for iOS?

The Location SDK for iOS provides fused location. Generally, the Location SDK for iOS first returns a location using the no-network location (offline network location) method, which is a fast location method. When a network connection is available, the Location SDK updates the location using the network location (online network location) method.

The network location method consists of the base station location and Wi-Fi location modes. When the Wi-Fi module is enabled, the Wi-Fi location mode will be used, regardless of whether a Wi-Fi connection is available. If the Wi-Fi module is disabled, the base station location mode will be used.

In outdoor scenarios, the device will utilize A-GPS to query satellite ephemeris online, and use connected GPS satellites to perform the location operation if GPS signals are received. (A-GPS is used for accelerating traversing of satellite ephemeris.)

iOS devices may switch between these location methods based on the current signal strength and network condition. With updates of iOS, the location rules may also change. Therefore, it is hard to tell whether the GPS location or network location method is used for location on iOS devices.

How can I set the Location SDK for iOS to return location updates based on the specified time interval and distance change?

You cannot set the Location SDK for iOS to specify the time interval and distance change for obtaining location updates.

The location capabilities in the Location SDK for iOS are encapsulated based on native location capabilities of iOS. Therefore, you cannot set the Location SDK for iOS to specify the time interval and distance change.

The native location capabilities of iOS provide two mechanisms for obtaining location updates:

  1. Obtain a location update by minimum distance change.

    You can call the following method to set the minimum distance change (in meters) for obtaining location updates. If the distance change between two location updates is greater than the specified minimum distance change, the Location SDK for iOS will return a location update meeting the requirements.

    self.locationManager.distanceFilter = 200;

  2. Obtain a location update as long as the device moves.

    A location update will be obtained as long as the iOS device moves, without depending on any time interval and distance change.

Does the Location SDK for iOS support hot update?

The Location SDK for iOS does not support hot update and is integrated as a static library.

The Location SDK for iOS has a large location error sometimes. Why?

The Location SDK for iOS completes the initial location operation using the base station or through the no-network base station location function, which usually has an error ranging from hundreds of meters to several kilometers. If Wi-Fi or satellite signals cannot be received later, this location error will be kept for all returned locations. To improve the location accuracy, you can enable the Wi-Fi function (regardless of whether a network connection is available), or place the device in an open area to receive satellite signals.

Solution: Wait for a while, enable the mobile data and Wi-Fi functions (which can be disabled after the location operation is complete), or go to an outdoor place.

Which coordinate system is used for the returned locations?

The coordinate system used depends on the geographical location. In the Chinese mainland, Hong Kong (China), and Macao (China), the GCJ02 coordinate system is used. In Taiwan (China) and regions outside China, the WGS84 coordinate system is used.

How can the Location SDK for iOS request the location permission in iOS 11?

iOS 11 has updated location permission settings. You can set the location permission as follows:

Declare the location permission in the Info.plist file of your project. You can set the permission as needed in the following ways:

For iOS 9 to iOS 10:

The NSLocationWhenInUseUsageDescription permission allows your app to obtain the location information when it runs in the foreground.

The NSLocationAlwaysUsageDescription permission allows your app to obtain the location information regardless of whether it runs in the foreground or background.

For iOS 11:

The NSLocationWhenInUseUsageDescription permission allows your app to obtain the location information when it runs in the foreground.

The NSLocationAlwaysAndWhenInUseUsageDescription permission allows your app to obtain the location information regardless of whether it runs in the foreground or background.

NOTE

If your app needs to use location functions in iOS 9 or later, you are advised to declare the NSLocationWhenInUseUsageDescription, NSLocationAlwaysUsageDescription, and NSLocationAlwaysAndWhenInUseUsageDescription permissions in the Info.plist file.

What should I do if error code 10803 or 10000 is returned when I use the Location SDK for iOS?

Before using capabilities of the Location SDK for iOS, you need to apply for required authorization. Do not use the location capabilities while applying for required authorization, and do not use the location capabilities immediately after setting the location permission and then switching to the app.

The heading and heading accuracy are both -1. Why?

If both the heading and heading accuracy are -1, the accuracy fails to be obtained. The heading information is not returned during network location. In this case, turn off the Wi-Fi and cellular network and perform GPS location. If the location operation is successful but no valid longitude and latitude are obtained, check the gyroscope on your device.

I have set the location accuracy to 100 meters or higher for continuous location, but no further location updates are received after I receive several location updates. Why?

Please wait patiently. There is a high probability that the continuous location is still in progress because the callback interval is long. You can move the device by a distance greater than or equal to the location accuracy, to help trigger location updates quickly. If the problem persists, submit a service ticket to us.

What should I do if App Store rejects my background location requests?

  1. To use the background location function, add the Privacy - Location Always Usage Description field to the Info.plist file of your project and set the field as needed. The figure below shows an example.

  2. Go to Signing & Capabilities and select Location updates in the Background Modes area.

  3. Wait for Apple's reviewer to approve your application. Generally, the reviewer will approve your application if they can easily find the service scenario for your app to use the background location function and your application reason is proper. You need to describe the actual reason of applying for the background location function or tell the reviewer how to trigger the background location function in the following situation: Your service scenario is hard to find or your application reason is improper. When the reviewer uses your app, they do not experience the background location function, but you have selected Location updates in the previous step. In most cases, the application will be approved.

Can my app request location updates when the device has no signal?

Scenario 1: [The device has no cellular or Wi-Fi signals, and has no network access.] The location operation can only be performed outdoors using GPS. The initial location request may take several minutes, but the time required for subsequent location requests will be normal.

Scenario 2: [The device has no cellular signals or network access, but has Wi-Fi signals.] If the device has accessed the network earlier around the current place and downloaded nearby Wi-Fi hotspot data, the location can be pinpointed using the no-network Wi-Fi location function. Otherwise, the processing is the same as that in scenario 1.

Scenario 3: [The device has no cellular signals, but has Wi-Fi signals and network access.] The location can be pinpointed using the Wi-Fi location function. In addition, data about Wi-Fi hotspots in a large area around the current location will be downloaded for subsequent use by the no-network Wi-Fi location function.

Scenario 4: [The device has cellular signals, but has no Wi-Fi signals and network access.] If the device can receive signals from important base stations built in iOS, these base stations will be used for no-network base station location. Otherwise, the location operation cannot be performed.

Scenario 5: [The device has cellular signals and network access, but has no Wi-Fi signals.] The base station and network are used for location. In addition, local important base station information may be updated.

Why cannot the location and heading information be obtained on a simulator?

You cannot obtain the heading information but can obtain the mock location information. Open the simulator, go to Features > Location, and select an option other than None.

REST API

What should I do if no file is generated for the geofence export and template download operations in the Firefox browser?

You need to modify Firefox settings. To do this, open the Firefox browser, enter about:config in the address box, and press Enter. On the settings page displayed, search for security.csp.enable, set it to false, and restart the Firefox browser.

What can I do if GeoLocation (API) (networklocation/v1/geoLocation) returns result code 403 or 405?

Sign in to AppGallery Connect, go to Project settings > Manage APIs, toggle the Location Kit switch off, toggle the switch on again, and try again later.