The way to find stuff that's close is just basic maths and some
optimisation
You can find the distance of any object with coörds x.y to object u.v
with the formula (in math.h speak) :
distance = sqrt(pow((x - u),2) + pow((y - v),2))
It's easy to calculate the maximum values that the coordinates of the
locations you're looking for can have, and you can query CoreData with
those bounding values. The result should be a list of locations that
are with certain min/max x and y values (= within a bounding square).
You can refine this list by using the formula above, and even use it
to sort on the nearest locations.
This way of working is quite quick because you don't have to do
calculations for every element in your database, only the ones that
you got back from within the bounding box. Very handy if you have
large datasets.
Have fun,
D.
(remark: if you're using actual longitude/latitude coördinates,
there's some more magic you need to perform to use real distances, but
I don't have them handy right now. A quick google returns this:
http://www.movable-type.co.uk/scripts/latlong.html )
(remark number 2: i remember some blog post from a long time ago by
the guy that made the Spots app that discusses this kind of stuff and
the optimisations he had to use to make his app perform well - but I
can't find it right now...)
On Aug 10, 11:28 am, Tom Nys <
tom....@gmail.com> wrote:
> Hi Stefaan,
>
> We indeed stored both latitude and longitude as 2 attributes in our coredata
> element.
>
> We prepopulate our database with a custom XML which contains all the
> elements. We use tinyxml as XML parsing library on iPhone/iPad, and for
> each XML element, we create a CoreData element. When all is created, we
> commit the changes to the database (all of this in a background thread using
> GCD).
>
> Hope this helps,
>
> Tom
>
> > ><
stefaan.les...@devia.be>wrote:
> > >>
cocoaheadsbe...@googlegroups.com<cocoaheadsbe%2Bunsubscribe@google
groups.com>
> > <
cocoaheadsbe%2Bunsu...@googlegroups.com<cocoaheadsbe%252Bunsubscribe@g
ooglegroups.com>
> > >
cocoaheadsbe...@googlegroups.com<cocoaheadsbe%2Bunsubscribe@google
groups.com>
> >
cocoaheadsbe...@googlegroups.com<cocoaheadsbe%2Bunsubscribe@google
groups.com>