Aman Aalam
Aman Aalam

Reputation: 11251

Calculating nearest GeoLocation out of a dataset

I will try to explain this with an example:

I have a data set of thousands of GeoLocations and some information attached with them, and have a script that interacts with this Dataset.

I will send this script a GeoLocation and will want it to send me a GeoLocation out from the dataset which is nearest to the GeoLocation I sent.

Is there any predefined logic/algorithm/formula available for this?

If not, what approach can I take?

Is it going to be as simple as applying normal math to it?

Upvotes: 1

Views: 599

Answers (2)

martincm
martincm

Reputation: 13

I was working on a similar problem last week and found this site.

http://www.imaginerc.com/software/GeoCalc/

It adds geo calculation functionallity to PHP and MySQL.

Martin

Upvotes: 0

Denis de Bernardy
Denis de Bernardy

Reputation: 78443

The usual way is to do a K-nearest search query, which can use an R-tree or GIST index.

Not all databases support this, however. Best I'm aware, SQLite doesn't, and I'm guessing you're using the latter since you're developing for Android. If so, look into this related question for a potential workaround:

SQlite Getting nearest locations (with latitude and longitude)

If not, look into PostGIS (for PostgreSQL), MySQL's GIS functionality, etc.

Upvotes: 1

Related Questions