Arvind
Arvind

Reputation: 543

How to get nearby locations from latitude/longitude?

I have store various latitude and longitude in database(Sqlite3) for various location. Now I have current latitude and longitude. How can I know nearest locations from current position. Please suggest.

Upvotes: 1

Views: 913

Answers (3)

Andras Zoltan
Andras Zoltan

Reputation: 42334

I dare say @Kongress answer is the best here - but I'm just going to chuck this one into the ring as the concept itself is one that I've dealt with before.

I can't tell you how to build one in objective-c, but for our lat/long reverse lookup I built a K-DTree from the lat longs in our database ( > 250,000) and it gives us sub-100-nanosecond lookups on desktop hardware. On an iphone it's still likely to be pretty fast - memory might be a concern though as you really need to be able to cache the instance in memory, to be really useful; it takes a little while to build it (ours builds in about 1.5 seconds).

Just an idea.

Upvotes: 0

Rob
Rob

Reputation: 7707

The syntax will likely need to change, but take a look at this question that uses MySQL. Essentially you want to create a rectangle with the current point at the center (most likely). Using the bounds of this new box, you can run your SQL query.

Upvotes: 0

Kongress
Kongress

Reputation: 2254

I assume you're talking about Reverse Geocoding. There's an Apple class provided for that, MKReverseGeocoder. There are also plenty of how-to discussions about that, such as here, here, etc.

Upvotes: 2

Related Questions