开发者

Searching for surrounding suburbs based on latitude & longitude using Objective C

I need to identify items of interest nearby to a particular latitude/longitude. I have two sets of objects stored in Core Data:

PostalArea
- latitude
- longitude
- postcode

Store
- name 
- latitude
- longitude

I need to be able to retrieve a record from the PostalArea table, and then find stores which are closeby.

Most of the examples I've found are SQL based. I'm hoping someone can assist me with getting this working wi开发者_开发百科th Core Data. Ideally I would like to limit the result set to a certain number (say, 10), as opposed to limiting it based on distance.

EDIT: pulling all the records into memory is an option, if need be.


The most common solution to this is to determine a min/max of both lat and long and then do a predicate based on those. That would narrow your search to within a circle and then with those remaining objects in memory you can sort by closest to the point.

Update

Once you have the objects in memory you can then do some fun things with them. For instance you could have a transient value called 'currentPoint' and you could then KVO on the resulting array such as:

[resultingArray setValue:aPoint forKey:@"currentPoint"];

Then you could have a method that returns the distance from that point which you can sort by.

That is one example, I am sure there are other ways but the general idea is to get a subset of locations into memory so that you can then calculate distance and finally sort.


How would you feel about a REST service option? Is you use the Google APIs, you can query for exactly those things. There are plenty of JSON interfaces available for Objective C.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜