3 ms·
A few years back I was working at a real estate firm where you could search for available rentals by location. The houses were saved with their latitude and lon
by hiyer 5y ago
A few years back I was working at a real estate firm where you could search for available rentals by location. The houses were saved with their latitude and longitude values. Their original search implementation used to fetch all the records from the database and then filter them based on some parameters - IIRC translate back from the lat-long to some location and check if it fell within the area. The number of rows was not too high - 10k or so, so this used to run in single-digit seconds.
At that time MySQL had neither spatial indices nor a native haversine method. I switched out the search method to translate the area name to a lat-long on the frontend (based on google maps) and then use a haversine in the query to retrieve results. It was still a couple of orders of magnitude faster than the previous solution, and more accurate to boot.