Clip
Clip

Reputation: 3078

Find nearest objects without lat/lon pari

I have about 2.2M objects which all contain a full address (street, state, zip), however none of them have a lat/lon pair.

How can I sort an array to find the nearest objects to a location? Is there a way to do it with the ZIP code?

Upvotes: 1

Views: 42

Answers (1)

rootatdarkstar
rootatdarkstar

Reputation: 1526

There is a few methods:

  1. You can find coordinates of location by address. This technique is called geocoding. IOS already have built-in classes to do that: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/UsingGeocoders/UsingGeocoders.html

  2. You also can use any other paydable geocoding service (like google) in any platform without rate restriction.

  3. Or you can do it by yourself with this https://gist.github.com/erichurst/7882666 by storing it in any local DB (like sqlite) and then associating object zipcode to its coordinates. And then find nearest zipcodes to your object - latitude/longitude find nearest latitude/longitude - complex sql or complex calculation It's not accurate method, but will work.

Upvotes: 0

Related Questions