Your question is Top 5 Closest Locations. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Life.Church receives location data as a JSON payload. Given the payload and a user's latitude and longitude, return the five closest Life.Church locations in ascending distance order.
Use the Haversine formula to calculate the great-circle distance between two latitude and longitude points. The payload is valid JSON with a top-level locations array. Each location contains a unique string id, a name, a numeric latitude, and a numeric longitude.
Because the payload may contain millions of locations, avoid sorting every location when selecting the result. Preserve the original input order when multiple locations have the same distance.
Implement parse_top_locations(payload, user_lat, user_lon), where payload is a JSON string, user_lat and user_lon are numbers in degrees, and the return value is a list containing up to five original location objects. Results must be ordered from closest to farthest.
def parse_top_locations(payload, user_lat, user_lon):