0.0.2 • Published 5 months ago
mock-location-detector v0.0.2
Mock Location Detector - Capacitor Plugin
Detect mock locations in Android, iOS, and Web using this Capacitor plugin.
Features
- ✅ Detects if mock location is enabled on Android.
- ✅ Detects software-simulated locations on iOS (iOS 15+ only).
- ✅ Provides a consistent API for Web, returning
false
.
Installation
Install the plugin via npm:
npm install mock-location-detector
npx cap sync
iOS Setup
For iOS, add the following keys to your Info.plist
file to request location permissions:
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need access to your location to check for mock locations.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need continuous access to location for detecting mock locations.</string>
Then, ensure your iOS project is synced:
npx cap sync ios
Android Setup
No additional setup is required for Android. Just ensure that your app has the ACCESS_FINE_LOCATION
permission.
Usage
Import and use the plugin in your Ionic/Capacitor project:
import { MockLocationDetector } from 'mock-location-detector';
async function checkMockLocation() {
try {
const result = await MockLocationDetector.isMockLocationEnabled();
console.log('Mock Location Enabled:', result.enabled);
} catch (error) {
console.error('Error checking mock location:', error);
}
}
Response Format
{
"enabled": true | false
}
true
→ Mock location is enabled.false
→ Mock location is not enabled.
Platform Support
Platform | Supported |
---|---|
Android | ✅ Yes |
iOS (15+) | ✅ Yes |
Web | ✅ Returns false |
License
This project is licensed under the MIT License.