Skip to content

Instantly share code, notes, and snippets.

@breautek
Last active October 31, 2022 08:48
Show Gist options
  • Save breautek/d6231fa33d6942c269296546892afb5e to your computer and use it in GitHub Desktop.
Save breautek/d6231fa33d6942c269296546892afb5e to your computer and use it in GitHub Desktop.
GPS Explained

GPS features is something I heavily use in my apps and in my experience there are two things that can effect slow/non-existent GPS updates.

1. User Settings

On most android versions, the user may have location mode set "battery saving" -- which makes it so the phone requires to be near networks such as known wifi hotspots (such as businesses), or near mobile towers because it only uses wifi & mobile networks to determine location. Or "Device Only", which means the phone must connect to satellites to obtain a location. From a cold fix, it can take 10-15 minutes even in good conditions on a decent device before you start seeing stable GPS updates. The best location setting the phone can be in is "High Accuracy" mode (not to be confused with the api's highAccuracy option), which allows the phone to use any number of strategies to obtain a GPS update as quickly as possible. Note that this is a user setting that is outside the control of the app, however I'm sure there are plugins that allows you to open up the appropriate settings screen for the user. I've seen other apps do it.

2. Poor Environment

Even with the phone has high accuracy enabled in their location settings. Being in a poor environment can hinder the ability to receive GPS events, or will cause received updates to have inaccurate results. The perfect environment to have stable GPS outsides is outside away from buildings, in clear skies weather. My work office is in a basement of a large building. If I require good accurate GPS events in my testing, I literally cannot do the test at my desk. No joke, if I have to I'd have to take my test device outside of the building and walk around in the parking lot. Alternatively I use a simulator where I have the ability to manually simulate GPS events as if they were coming from the GPS hardware. I'd also like to note that this issue is not exclusive to Cordova. Any app, whether it be Google Maps, or something else that shows your location all exhibit location troubles when I'm in my workplace building.

In my apps, I use another third-party plugin called the Diagnostic plugin in conjunction with the geolocation plugin. It provides several APIs to figure out the current state of required features. Such as if the user has granted permissions, or if the GPS feature is turned off completely etc. I use this to provide helpful feedback to the user if they need to change something. https://github.com/dpa99c/cordova-diagnostic-plugin

3. The Checklist This checklist is a bulletpoint list of some things that should be checked when having slow/unresponsive or inaccurate GPS readings, but it isn't a complete list.

  • The phone has High Accuracy enabled in their location settings.
  • The phone has Improved Accuracy enabled, (some android phones they offer individual settings for Wi-Fi scanning and Bluetooth scanning).
  • I am not in any of the following locations:
  • A large building
  • A basement
  • Surrounded by tall buildings and/or mountains.

I hope this information helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment