How to Explore Real-time Geolocation Solutions
This how-to will explain real-time geolocation services for developers, what to consider while building geolocation features, and how PubNub can make it easy to stream and use real-time location data.
Location-based apps offer an excellent way to take your application to the next level by making the user experience more complete and more engaging. Location can be used along with your core features to do more and make it easier to use what you create. Before you build, let's evaluate why you need location services and when you should and can use location services. Next, we’ll cover geolocation and geohashing related problems to consider and how PubNub can solve them so you can focus on building your app.
Why do you need real-time geolocation tracking services?
Let’s start by taking a few steps back so you can fully understand why you need geolocation in your apps. Consider this: pretend you're building one of the first food delivery apps *without* geolocation for the first iPhones that didnt have GPS. When your users first open the app they first have to input a region to search for restaurants. Next, they manually check each restaurant address to ensure it’s in range and can be delivered to their home. Then the user has to again put in their address so that the delivery driver can use a separate mapping service to plot the best route to make deliveries (remember MapQuest?). With all these steps it becomes clear why delivery services really caught on after location services became more popular.
Today, a user will open your app to automatically populate restaurants based on their location and range. The delivery driver can then make deliveries that are automatically managed and efficiently plotted by the app. This is the frictionless and easy experience that’s expected and is now a requirement to provide location aware services wherever you can.
“In 2022, the number of smartphone users in the world today is 6.648 Billion, which translates to 83.72% of the world’s population owning a smartphone. (Source: https://www.bankmycell.com/blog/how-many-phones-are-in-the-world)”
With a majority of the world’s population owning a smartphone and GPS services being standard for most devices almost any industry can benefit from building location services in their software. Gaming, logistics, social media, retail/eCommerce, and advertising are all examples of applications or industries that work, convert, and offer better experiences if you have location-aware services. Next, let’s explore each of these use cases and why geolocation is an essential requirement for a great user experience.
Use cases for real-time geolocation tracking services
Each use case has opportunities to use geolocation services in different ways so we’ll take a look at a few example use cases to give you some ideas for incorporating geolocation into your application.
Gaming
Location aware games are exciting for players because they offer an additional layer to the experience that makes it stand out. Most often location aware games use geolocation services to customize the experience based on where the user is and geolocation services are often used with Augmented Reality to combine the virtual world with the real world. For example, Pokemon Go, a 2016 augmented reality mobile game, requires geolocation services to “discover and capture the Pokémon all around you” while competing with other players. In Pokemon Go the entire experience of the game is focused around location and exploring the world around you. Pokemon Go has been so successful that 6 years later people are still playing and the game has been downloaded over a billion times.
Logistics
Logistics keeps the world moving. Trucks, boats, and planes never stop to ensure the world keeps moving stuff from point A to point B. In 2020 Parcel shipping exceeded 131 billion in volume worldwide, and it's likely to more than double by 2026, according to Pitney Bowes Parcel Shipping Index. With all of that movement there’s a lot to keep track of and a lot of room for efficiency improvement. Most logistics companies today use geolocation systems that provide real-time information to track and monitor their fleet’s location,speed, distance traveled, routes taken, as well as other telemetry data. Using geolocation services, logistics applications can plan productive routes, track cargo in real-time, maintain driver performance and safety, and even ensure security using geo-fencing (a virtual perimeter) when a specific vehicle or cargo leaves or enters an area or location.
Social Media
Social media keeps us connected in real-time anywhere in the world. It can also keep us connected to wherever you are by customizing the experience to better match your local environment. It wouldn't make a lot of sense for LinkedIn to suggest an in-person job on the other side of the world from you. However, it would make sense for LinkedIn to suggest a job nearby. Users want to be connected to the local world around them and for social networks to do that they have to know where you are and where you spend time. geolocation makes it simpler to make local recommendations and connections that drive a better overall experience for users.
Retail / eCommerce
During the Covid Pandemic many people experimented with placing orders online for local pickup for the first time. geolocation is necessary for getting the user’s current location and connecting them to pick up the order from the nearest store. By simplifying the ordering process as much as possible it enables users to buy things without any blockers and with the further benefit of no crowds, no lines, and no need to wait for delivery. Walmart even took this a step further with their app: It uses geo-fencing to know in real-time when you arrive at the store for a pickup - simplifying the pickup process even more!
Advertising
Geo-aware targeting or geo-targeting uses real-time location data to serve advertisements relevant to users. Using geo-targeting advertisers can ensure they are reaching the right people at the right time. This prevents users from seeing boring ads that aren't relevant to their interests and ensures advertisers are maximizing their budget. In addition to targeting, advertisers use geolocation to increase audience engagement, enhance user experience, gain audience insights, and track and attribute performance.
Common Problems Building Geolocation Features
Real-time geolocation features are hard to build and there are some challenges you should be aware of before getting started. This is not an exhaustive list - these are the some common issues we see:
Inaccurate and Imprecise Data
There are a lot of variables involved in collecting GPS data. The most common issue is poor signal quality and signal reflections. In some environments, like in dense cities, getting clear signals from GPS satellites can be almost impossible. To make matters worse GPS signals can reflect off of structures and objects causing the wrong location to show entirely! The type of device you have and even how you’re holding it can also have an impact. So what can you do about it? Many devices and geolocation APIs for collecting location data try to use more than just GPS signals for identifying location. Nearby WiFi networks, cellular towers, and Bluetooth are often used to assist GPS and help hone in an exact location. It’s still not perfect, and when you’re moving around it’s often even worse. If you know where the users are supposed to be, for example if they are supposed to be following a route, then you can usually take advantage of your selected map SDK to ‘snap’ the location to the nearest point of the route. Another technique is to create a GPS data point smoothing filter, such as a simple Kalman filter. The basic idea of smoothing filters is to reduce erratic data points used for providing the GPS position.
Battery Life
To collect accurate data you’re often using the GPS receiver, WiFi, Cellular, and Bluetooth all at the same time. It shouldn't be a surprise that that will take a toll on battery life. The best way to solve this problem is to use it only when you need it. If you’re building a ride-sharing app you could collect continuous location updates of the riders, but if you do that impacts battery life. Instead figure out how often you actually need to update the location, such as every 10-30 seconds, and then stop updating it once they get in the ride. On the other side (driver’s side of the app) their device is almost always plugged in and charging - so take advantage and provide more and continuous updates.
Picking a Map SDK
You could use any Map SDK but you should use one that offers the features you need. Many of the most popular options will have similar feature sets so you should also consider flexibility of implementing and price. At PubNub we usually recommend MapBox or Google Maps. MapBox is more customizable than Google Maps, but it is tricky to make it your own. Two important things to think about are:
Can you customize it in the way you need? Many apps require a custom UI/UX. If you’re updating the points and paths in real-time make sure it works the way you want and expect.
What geolocation Features are built in? Many mapping SDKs will handle features like route snapping, geo-fencing, geo-notifications, and path plotting for you. If you plan to use these features then you should check the map SDK you pick supports them. Otherwise, you’ll need to build these features yourself.
Difficulty Streaming and Sharing Geolocation Data
Most of the information you’ll find about building location aware apps focuses on collecting GPS data and displaying it, but there is little information about transmitting the GPS data from your users. Usually, you’d have to build the infrastructure and your own APIs, manage scaling, and manage security yourself to facilitate moving the GPS data around in real-time. You’ll also need to make sure your API is always available and working fast enough for a good user experience. With GPS data this can be tricky because all of those location updates can take a toll on any server (and any developer). The good news is that there is an easier way to transmit GPS data across devices - without setting up a backend and without worrying about scale.
PubNub’s primary product is a real-time publish/subscribe messaging API built on a global Data Stream Network. Messages sent with PubNub are delivered in under 0.25 seconds, and PubNub supports dozens of SDKs in most programming languages. PubNub provides the secure, scalable, and reliable infrastructure to power any real-time application - and PubNub APIs work great for transmitting GPS data.
Why PubNub + Geolocation Services?
A big issue geolocation apps face is scaling. When you’re transmitting geolocation updates, sometimes multiple times a seconds from a single user, it’s tricky to manage while also keeping latency down. Depending on the application you may also have to deal with unexpected traffic surges and then idle servers that continue to cost you money. Using PubNub you can eliminate these problems and only pay for the traffic you use. PubNub also provides a 99.999% SLA on all of its services - so you never need to worry about downtime. This makes it possible to scale to billions of users without touching a single server or creating a backend. You can focus on building your application and let the backend ‘just work.'
You can also process and filter geolocation data in real-time with PubNub Functions. PubNub Functions is a serverless environment to execute functions on messages as they route through the PubNub Network. You can incorporate logic like re-routing, augmenting, filtering, transforming, and aggregating data. You can make location error corrections or trigger push notificationsfrom PubNub before the data is received by any users.
Interested in exploring more about PubNub and geolocation? Here are some resources to look at next:
Need more help with building geolocation services with PubNub? Get in touch with our sales team and let's discuss all the possibilities.