I'm trying to find a clever/efficient way to calculate the the farthest point from an origin, given a list of lat,lng points.
For example, if trying to find the closest point from an origin I could adapt this function that finds all nearby points:
def getNearby(origin_dict, geo_dict_list, radius_miles): # adapted from http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL # this will create a lat+lng square # corners aren't not technically correct, but the general idea: # lat_1 ---> lng_1 # | | # | | # | | # lat_2 ---> lng_2 # if geo point is inside our lat+lng square, then do expensive calculation of exact distance # to see if it's inside the radius-circle w/in the square (circle not shown) # geo_dict_list = [ {'lat' : 1.234, 'lng' : 5.678}, ... ] offset = radius_miles / 69.1 lat_1 = origin_dict['lat'] - offset lat_2 = origin_dict['lat'] + offset offset = radius_miles / abs( math.cos( math.radians(origin_dict['lat']) ) * 69.1 ) lng_1 = origin_dict['lng'] - offset lng_2 = origin_dict['lng'] + offset return_indexes = [] for index, geo_dict in enumerate(geo_dict_list): if (geo_dict['lat'] >= lat_1) and (geo_dict['lat'] = lng_1) and (geo_dict['lng']
For example, if trying to find the closest point from an origin I could adapt this function that finds all nearby points:
def getNearby(origin_dict, geo_dict_list, radius_miles): # adapted from http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL # this will create a lat+lng square # corners aren't not technically correct, but the general idea: # lat_1 ---> lng_1 # | | # | | # | | # lat_2 ---> lng_2 # if geo point is inside our lat+lng square, then do expensive calculation of exact distance # to see if it's inside the radius-circle w/in the square (circle not shown) # geo_dict_list = [ {'lat' : 1.234, 'lng' : 5.678}, ... ] offset = radius_miles / 69.1 lat_1 = origin_dict['lat'] - offset lat_2 = origin_dict['lat'] + offset offset = radius_miles / abs( math.cos( math.radians(origin_dict['lat']) ) * 69.1 ) lng_1 = origin_dict['lng'] - offset lng_2 = origin_dict['lng'] + offset return_indexes = [] for index, geo_dict in enumerate(geo_dict_list): if (geo_dict['lat'] >= lat_1) and (geo_dict['lat'] = lng_1) and (geo_dict['lng']