Determining the location on Android

AppMetrica can determine the location of a device. Location accuracy depends on the configuration that the library uses for initialization:
With the locationTracking option enabled
Note.

For iOS, the option is enabled by default.

The location is determined with accuracy to the city. You can retrieve this information in reports and via the Logs API.

The app requests GPS access. Battery consumption may increase.

With the locationTracking option disabled
Note.

Starting with the Android AppMetrica SDK 5.0.0, the locationTracking option is disabled by default.

If the version is lower than 5.0.0, the locationTracking option is enabled by default.

The location is determined by the IP address with accuracy to the country. You can retrieve this information in reports, but not via the Logs API.

The app requests GPS access. Battery consumption does not increase.

Note. If you have enabled IP address masking, AppMetrica determines location with the accuracy to the country by the unmasked part of the IP address.

How to enable location determination

Note.

Starting with version 5.0.0, the AppMetrica SDK is initialized with locationTracking disabled by default.

To initialize a library with locationTracking enabled, pass true to the withLocationTracking(boolean enabled) method when creating an extended library configuration:
// Creating an extended library configuration.
        YandexMetricaConfig config = YandexMetricaConfig.newConfigBuilder(API_key)
        // Enabling the data sending about the device location.
        .withLocationTracking(true)
        .build();
        // Initializing the AppMetrica SDK.
        YandexMetrica.activate(getApplicationContext(), config);
Copied to clipboard

To enable locationTracking after initializing the library, use the YandexMetrica.setLocationTracking(boolean enabled) method:

YandexMetrica.setLocationTracking(true);
Copied to clipboard

To determine the location more precisely, add to the AndroidManifest.xml file one of the following permissions:

For example:

<manifest>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <application>...</application>
</manifest>
Copied to clipboard

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.