I’m trying to write a search by location into a website. I cant help but think that the code I’ve written is not very efficient.
If I were to have 1000’s of places it would be fairly slow.
This is a psuedo version.
import haversine class Place(db.Model): name = "TEST" lat = 52 lng = -2.5 def get_places(): return Place.query.all() def sort_by_dist(current_lat,current_lng,limit=10): return sorted(get_places(), key=lambda x:haversine((current_lat,current_lng),(x.lat,x.lng)))(:limit)