How to Build a Geographically-aware, Location-based Android Dating App

I built an app to rig the chances of me getting a date.

With over a  call.

Calculating Distance in Realtime

We’ll be getting the data in the form of an array. The first two elements of the array are the IDs of the user and the last two elements are the location of the user who initiated the request. The first element is the ID of the initiator, and the second is a possible swipe candidate. Once we finish the calculation, we’ll send the ID of the unique user and the distance they are from the initiator.

The result of this function will look like this:

{ "ID": "Unique User ID", "distance": 5 }

How to Swipe Through Users on the Android App

To start off, create an empty Android Studio project with Kotlin support checked.

Next, look at the dependencies we’re going to add to our app-level Gradle file to ensure our application runs smoothly.

The first dependency is the PubNub SDK, which will help us publish and subscribe to the logic we just created. Related to the PubNub SDK, we’ll also need our Publish and Subscribe keys. You can get your publish and subscribe keys by going through the quick setup below.

The other dependencies needed are for the visual component of our application — the swiping functionality.

Creating the User Interface

First, we’ll adjust our activity_main.xml to accommodate for our swiping feature that’ll be initialized in our MainActivity.kt file.

Next, we’ll create each profile card’s UI, as well as the overlay on each of them, taking into consideration whether the user is swiping to the left or right.

That’s it for the UI, now let’s cover the backend.

Integrating the Application Logic

For our application to be complete we’ll be creating four separate files. The first file we’re going to need is a class that will act as an object for each profile and will contain the related information.

Next, we’re going to create a file that will have some helper functions to update our collection of profiles.

Now, we can load each profile into the frontend. We’ll do this within a class called the CardStackAdapter.

Stitching Everything Together

We can head over to the MainActivity.kt file to see how everything fits together.

Let’s have a quick look at the onCreate and onStart methods.

We can break down everything that’s happening into three things.

First, we’ll get the location of the device using Fused Location. Next, we’ll subscribe to a channel with the same name as our device ID, since all the possible people we can swipe on are published to that channel. Lastly, in the onStart, we’ll be publishing the date related to the device, just like the ID and Location. The reason we publish in the onStart and not the onCreate is because we won’t be able to get all the information we need to publish until the activity starts.

With that, let’s add all the features and using your pub/sub keys (they’re in your Admin Dashboard), in our MainActivity. In the end, our file will look like this:

Let’s run the app! In either an emulator or on a device, you can see the swiping functionality, as well as the user’s distance from you.

Nice work! Want to explore more features and ideas around mobile dating apps? Check out our realtime dating apps overview, and see how you can power cross-platform, fast, and secure dating apps at global scale with PubNub’s chat APIs and messaging infrastructure.

Originally published at

How to Build a Geographically-aware, Location-based Android Dating App was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.