0

I am building both an Android and IOS app that will use a user's GPS location. I am concerned about a user faking a their GPS location as I've heard people doing with Uber.

Is there a programmatic way of preventing or detecting this?

now_world
  • 940
  • 7
  • 21
  • 56

2 Answers2

2

There is pretty much no way to validate the correctness of your GPS readings. However, there are workarounds you could use to detect possible spoofing:

First, you can detect if they Mock Location setting is on (which is commonly used by GPS faking apps). To do so, lookup Settings.Secure.ALLOW_MOCK_LOCATION) setting and check if it's enabled or not. Then check which apps have that permission (namely android.permission.ACCESS_MOCK_LOCATION). If there are apps present that use that permission and that setting is on, there is a high change they may be faking user's location.

You could also try to use Location.isFromMockProvider, although I am not sure how accurate the result is. The function returns true if the location you're checking has been acquired through a GPS faking app.

altskop
  • 311
  • 2
  • 12
0

I'm not sure, but if someone want to give fake GPS location, he need to have rooted phone. So you can check, that if someone has rooted phone, then don't trust his/her location. To check if phone is rooted: link

Panczur
  • 633
  • 1
  • 9
  • 26
  • Rooting on its own, of course, doesn't necessarily mean you fake your location. It's almost like saying "if that person has a gun, he's likely a killer". Excluding all rooted phones from your user auditory is a significant hit, which I wouldn't advise to take upon yourself if you can help it. Instead of checking, whether the phone is rooted, I'd advise checking, whether the option for GPS faking is enabled (see my answer for details) – altskop Jul 26 '17 at 16:53
  • I don't need to root my phone to fake my GPS location. – yusufmalikul Jun 21 '21 at 07:31