Detect or avoid mock GPS location


#1

Hello, is there any way to detect when one of my users tring to send me fake location?
im building an app that must get the correct and accurate location of the user.

thanks!


#2

I have a plugin called “FakeLocation” for cordova (only for Android devices) that does what you want. I hope it helps you.

Installation:

cordova plugin add https://github.com/tomloprod/cordova-plugin-fakelocation.git

Usage:

window.plugins.fakeLocation.check(function(IsEnabledMockLocations){
    console.log(IsEnabledMockLocations);
});

###Github:


#3

Hi… can you explain detailed how to configure with ionic?? pls help


#4

There is no configuration for this plugin. Yoy only need to call check method and this will return a boolean. true if it’s enabled mock locations and false if not.

window.plugins.fakeLocation.check(function(IsEnabledMockLocations){
    if(IsEnabledMockLocations){
        console.log("This device has mock locations enabled");
    }else{
        console.log("This device has not mock locations enabled");
    }
});

#6

But In Motorola E3 mobile there is no Allow Mock Locations Settings. There is setting called “Select mock Location App”. I have selected Fake GPS app. But the plugin is returning false in this case. What to do for this?


#7

From what I see, in Android Marshmallow this doesn’t work anymore . I will try to get it work in my free time; of course, any PR is welcome :slight_smile:


#8

Can you Please give me any idea to this. I will try to implement. I am a java Developer I don’t know Android and Objective C. If give me any tip for this that will be helpful for me.


#9

Maybe this answer would help you to implement this funcionality:


#10

@tomloprod This answer is explaining about whether my app is access to the mock locations or not. But my requirement is, If any one of the app is set to access the mock Geo location then I have to notify the user to turn of it.


#11

Yes, I know. But this answer can be modified to adapt to your requirements.


#12

@tomloprod Hi,
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
AppOpsManager opsManager = (AppOpsManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.APP_OPS_SERVICE);
PackageManager pm = this.cordova.getActivity().getApplicationContext().getPackageManager();
List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
if (opsManager.checkOp(AppOpsManager.OPSTR_MOCK_LOCATION, applicationInfo.uid, applicationInfo.packageName)== AppOpsManager.MODE_ALLOWED) {
callbackContext.success(1);
break;
}
}
}
is throwing an exception "uid 10214 does not have android.permission.UPDATE_APP_OPS_STATS."
How to get the uid of the application.


#13

Hi Krishna, please, open an issue on github and I will try to get it work on my free time. Okay? (I guess you have created a fork of my repo, so you can do your tests too)

I think a possible workaround is to use the stackoverflow´s answer with a loop of the installed apps … But it’s an assumption.


#14

How to use this in typescript2? i can’t use the plugin and i get the following error when using the following code

window.plugins.fakeLocation.check(function(IsEnabledMockLocations){
if(IsEnabledMockLocations){
    console.log("This device has mock locations enabled");
}else{
    console.log("This device has not mock locations enabled");
}
});

#15

Any news?
I can’t install the plugin https://github.com/tomloprod/cordova-plugin-fakelocation , it throws an error.


#16

Galera tentem usar para ionic 2/3:
window[‘plugins’].fakeLocation.check(function (IsEnabledMockLocations) {
console.log(IsEnabledMockLocations);
});

No lugar de window.plugins troque para window[‘plugins’].