How to have location tracking in your app, anonymous and without internet

Rubicon Cloud Advisor
3 min readMar 6, 2020

--

Using the GPS sensor and internet in our mobile apps is a great way to provide personalized content to the user. But using GPS and internet can be tricky when you want to ensure privacy. Collecting coordinates isn’t something users are very fond of. Who knows what happens with that data? But we can still offer that great user experience without collecting coordinates.

I walked into this issue when I started working on a mobile app for one of my clients. The app needed to show country specific content when the user visits another country. By using the GPS capabilities of the device we would be able to track down the user’s location. The coordinates will need to be translated into the name of the country so that the right content can be shown.

Without internet?

To summarize, these are the requirements:

  • Get the user’s location
  • Determine the name of the country of where the user is
  • Show the country specific content

Sounds like a doable task, right? But wait… there is one more requirement:

  • You are not allowed to use an internet connection

If we could use an internet connection, things would be easy. We could simply use a reverse geocoder (that both iOS and Android have) to convert the users coordinates into the name of the country. Unfortunately, these geocoders use an internet connection. So I need to translate coordinates into the name of the country without an internet connection.

Hmm… challenge accepted!

One approach would be to use region monitoring. Both iOS and Android have an API available to register a region to be monitored, once a user enters that region the app will be notified. In our case we would need to register an area for each country of the world. Sadly, this won’t work for iOS because you can register only 20 regions at the same time. And Android has a same kind of limitation.

Say hello to GeoJSON

Fortunately, there is another approach. GeoJSON is an open standard to describe geographical objects with coordinates in a JSON format. And online are multiple free GeoJSON sources for all kinds of objects. Here is an example:

GeoJSON example

The coordinates in the JSON define the square box inside the picture. Metadata such as the country code is stored in the “properties” section.

In our use case we’ll want to know the outlining coordinates for each country. Luckily there is already a website for that: https://geojson-maps.ash.ms

To play around with GeoJSON you can visit: http://geojson.io.

So how does it work?

The app still receives the user’s location. But this time, the app loops through the countries in the GeoJSON file and check if the coordinates lies within one of the outlines. When there is a match, we can get the name of the country via the “properties”. Now we have enough information to show the user, for example: “Hello welcome in Germany” without any internet connection.

Tweak GPS updates

To preserve the battery of the phone it is important to minimize location tracking. You won’t need to retrieve the users coordinates every second or every meter they traveled. Both iOS and Android have API’s that only give location updates after a specific distance. This will reduce the number of location updates dramatically.

And next to the amount of updates we can also adjust the coordinates precision. Location updates can be retrieved in two ways. Based on cellular towers or using the more energy consuming GPS chip. In our case using the cellular towers will be more than enough.

Conclusion

Using GeoJSON instead of internet is a valid alternative to provide location based features in mobile apps. You can guarantee your users that their location will only be used within the app and not send over the line. So if you’re building a mobile app and need location tracking, consider using GeoJSON!

--

--

Rubicon Cloud Advisor
Rubicon Cloud Advisor

Written by Rubicon Cloud Advisor

Solutions built on and born in the cloud

No responses yet