Searching for nearby users


I’ve had an idea for a new app.

One of the things I need to do in it is search for nearby users of the app.

I have been thinking of using gps location, uploading it to an online database and then searching for gps coordinates nearby. However, I think this will take a phone far too long to do and the more users there are the longer it will take.

Does anyone know how these kinds of apps are made and what databases/spreadsheets they use?


If the phone already has the GPS turned on, then getting the location from within the app is instant.

You can also limit the range of those near you with some good logic on the lat/long/distance

Using Firebase, you will get near instant updates. I don’t see a better more broad way to do it.

A few notes

NFC - you need to be within a meter or so.
WIFI - you need to be on the same network, or still have location services turned on.
Bluetooth - only has the capacity to handle 7 simultaneous connections, and is very limited on range.


I’ve been thinking about firebase but you can only have 100 simultaneous connections which I think means only 100 people can be logged into it at one time.

Do you know if that’s correct?


You can have 100k+ connections if you want to pay for it. And a connection is not an individual user. One user could count for a few connections depending on how you have it setup.


To begin with I’m looking at a free option. If enough people us the app I’ll monetise it and pay for database storage.

I’m leaning towards some kind of spreadsheet for now but need to work out how I can make it secure. I won’t be storing any personal truly info like real names, phone numbers etc. Just a randomly generated user name and some interests/hobbies a person has.


A spreadsheet solution will be too slow and too expensive for scaling.


Apart from firebase are there any other databases that have good storage and are fast but also allow a decent number of connections?


For free… very few. Amazon and MSFT have database types. And they do not have components for Thunkable, so you would have to build your own extension or hope you can use a REST API.

Some other options


I’ve been looking at firebase a bit more. I might use it and monetise my app via ads right from when I launch it. That way if enough people use it and I have to pay for extra usage above what’s free then I’ll have the funds to pay for it.


This is pretty easy to achieve with any SQL database (MySQL, MSSQL, Postgres etc) provided that you have user geocoordinates stored in the database (latitude and longitude)… something like:

select id, name, ..., ($earthRadius * acos( cos( radians($latitude) ) * cos( radians( users.latitude ) ) * cos( radians( users.longitude ) - radians($longitude) ) + sin( radians($latitude) ) * sin( radians( users.latitude ) ) ) ) as distance from users having distance <= $radius order by distance

Depending if you want distance in kilometers or miles, you’d replace $earthRadius with 6371 or with 3959 if you want it in miles (approximate radius of the Earth in km/mi).

Replace $latitude and $longitude with currently logged user’s latitude and longitude respectively
Replace $radius with the desired radius (in km/miles depending on what you’ve set for earth radius).

You can also add limit 100 at the end to limit results to 100 entries for example.

SQL query like this can handle/search millions of entries (users) without (m)any issues.

You can find pretty cheap sql database hosting today. Basically every web hosting offers mysql hosting in their hosting plans.

While not supported out-of-the-box, the project linked in my signature provides easy rest api for sql databases and since it is open source, it can be easily extended to support location-based queries.


I’m not sure which project you’re referring to in your signature.

I don’t have a PC or laptop, I create everything on my iPad.

These are my requirements:

  1. An online database. If I can’t get mysql database then firebase will have to do.

  2. A way for a user to upload their location and interests to the database. I only want to save their username and interests permanently. Their location will be deleted once they log out of the app. Then:

  3. A way for the app to search for nearby users who share some or all of their interests. Then:

  4. A way for a user to connect and chat to another user who shares the same or similar interest. Then:

  5. When a user logs out of the app (ie they go “offline”) the database needs to delete their record.

  6. I need to ensure usernames are unique.

If I use Firebase I have the beginning of an idea on how to achieve the above.

If I use a mysql database I will need to learn a lot of programming and new stuff. I don’t mind doing it if it’s worth the payoff.


The project I mentioned is Breadly: a php-powered web based database administration tool which also provides REST api so you can read/write the data from a third party app (like your Thunkable app). By no means it is required to use it to achieve what you want, I just mentioned it because I thought it could be useful in your use case.

Well, for most things probably. For example, Firebase would be much better choice for real-time chat than php/mysql. Or some kind of a socket server, whatever keeps the connection alive.


I had a look at Breadly and it seems interesting.

But you’re saying Firebase would be better for a chat app.

Do you think it would be better for me to save every user’s details in a Firebase Database (even if there are millions one day, I hope) and to search the Firebase Database for nearby users?

Also how would I use the equation you provided as Thunkable only does basic trigonometry?


That equation I provided is a part of SQL query which is executed on your database server (by PHP or any other server side language) and not within your app. I’m not sure how you could facilitate it within your app (with firebase) except to go through all your registered users, calculate the distance using formula above for each one of them and exclude those not within your desired radius.

Even though you can do all those calculations in Thunkable (see image below), calculating all those distances on all users would probably take too much time and it would take more time the more users you have. I’m not really familiar with Firebase but from what I searched online, I couldn’t find any way to query Firebase database by geospatial data like you can in SQL.

(in the last block you’d choose “degrees to radians”)


Thanks for that.

I’ve created a free online mysql database which seems to have enough features to get me started. Also I’ve learnt a little SQL as well and it makes some sense.

My next task is to understand SQL fully, how to use the database I’ve signed up to (if it lets me use my iPad) and learn how to use Breadly.

Then once all that is done I need to figure out how to make the actual chat itself


The more I look into all this, the more confused I become.

I think I might give up.


just do it step by step…

Check out the Thunkable YouTube channel, there are lots of great videos for getting started:

A very good way to learn App Inventor is to read the free Inventor’s Manual here in the AI2 free online eBook … the links are at the bottom of the Web page. The book ‘teaches’ users how to program with AI2 blocks.
There is a free programming course here and the aia files for the projects in the book are here:
How to do a lot of basic things with App Inventor are described here: .

Also do the tutorials to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor


Thanks for your advice. I’ve decided to come back to it one more time.

Here is what I think I need to do:

  1. Create a mysql database that will store user details such as id, language, interests.

  2. Create a php code that will allow an android app to connect to the database.

  3. Create an app that will contain the url for the database, my username for the database and my password for the database. The app will then access the database and use a SELECT command to find users with similar interests etc. The app will then create a chatroom for both users.

Is this all correct?


App Inventor - MySQL interface



Your DB credentials should be stored on your server (in PHP), not in your app. You can then use what Taifun proposed, or what I linked in one of my previous posts (Breadly) if you don’t know/want to write SQL (at least for some simpler bread operations)