Find best longitude/latitude match from an array of possible locations
I have a plist with 12 objects with unique keys (let's say 1, 2, 3, etc). Each object contains an array (key: clubLocations
) with 100 - 200 objects.
Each object in the clubLocations
array contains a longitude
and latitude
key with a club's location.
I would like some assistance in creating a method which loops through each object for 开发者_如何学JAVAevery clubLocations in every 12 objects and finds out which clubLocation is the closest match to the users coordinates.
So basically object 1/2/3/etc -> clubLocations objectAtIndex:0/1/2/3/etc -> best match?
I have the user's coordinates, so "just" need assistance to find the closest locations from my plist. Thank you in advance and please do not hesitate to ask in a comment if I am not making myself clear enough.
In pseudocode:
min_distance = MAXINT
closest = None
for obj in objects:
for club in obj.clubLocations:
d = distance(club.longitude, club.latitude, user.longitude, user.latitude)
if d < min_distance:
min_distance = d
closest = club
精彩评论