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?
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.