Geofence & Location
By default, Netmera SDK does not collect location information from the device. To use features like geofence messaging and location-based user targeting, you must enable location tracking.
Checking and Requesting Location Permission
Users may select "Only Once", "While Using the App", or "Always" when prompted for location permission. However, they can later change this permission via system settings.
To ensure accurate location tracking, always check the current system-level location permission before accessing any location-based features. If the required permission is missing or no longer valid, re-trigger the location permission request using Netmera.
What to do:
Check the current location permission status.
If the permission is missing or limited:
Request location permission again via Netmera.
Always ensure the necessary permission is granted before initializing any location-based operations.
Step 1: Enable Location History
To use location-based targeting, enable Location History in the Netmera web panel: Developers > App Info > App Config > Location History Enabled
Step 2: iOS Integration
1. Configure Location Permissions
Add the following edit-config
entries to the ios
section of your config.xml
to include the required Info.plist keys for location permissions:
<platform name="ios">
...
<edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
<string>Location access is needed to show nearby places.</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSLocationAlwaysUsageDescription">
<string>Location services will be used in the background as well.</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSLocationAlwaysAndWhenInUseUsageDescription">
<string>This app wants to use your location both when open and in the background.</string>
</edit-config>
...
</platform>
Step 3: Android Integration
On Android 10 and later, geofence push notifications require background location access. However, Android does not allow apps to request this permission directly in the app. Instead, users must manually enable "Allow all the time" in the system settings.
Best Practice: Before redirecting users to settings, display an explanatory message about why location access is needed. You can use Netmera widgets to communicate this effectively. You may see the next page Background Location Permission on how to create these widgets to ask for location permissions.
1. Add Required Permissions
Add the following edit-config
entries to the android section of your config.xml
<platform name="android">
...
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
...
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:networkSecurityConfig="@xml/network_security_config" />
<application android:name="com.netmera.cordova.plugin.NetmeraApplication" />
...
</edit-config>
...
</platform>
Step 4: Location Authorization
For iOS and Android 6.0 (API Level 23) and later, location permission must be requested while the app is running. Netmera provides a built-in permission request flow:
Netmera.askLocationAuthorization()
Calling these methods immediately prompts the location permission dialog. Make sure to inform users beforehand about how your application will use their location.
Last updated
Was this helpful?