1

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?

Clip
  • 3,018
  • 8
  • 42
  • 77
  • Update your data with coordinates. – rmaddy Jun 04 '16 at 01:18
  • @rmaddy There is nearly 2.2M objects, thats going to cost quite a bit. I'm hoping there is another way. – Clip Jun 04 '16 at 01:21
  • 1
    You only need to update the data once. Otherwise you have to do very expensive lookup for every record every time you wish to sort. – rmaddy Jun 04 '16 at 01:23
  • Why did you revert the tags? Your question has absolutely nothing at all to do with Objective-C. – rmaddy Jun 04 '16 at 01:24
  • @rmaddy Because my question has absolutely nothing to do with iOS. I didn't even mention iOS or an app anywhere in my question. This could be about OS X, or even a command line program. – Clip Jun 04 '16 at 10:46

1 Answers1

0

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.

Community
  • 1
  • 1
rootatdarkstar
  • 1,486
  • 2
  • 15
  • 26