Tuned in the Radar search function today
Today I improved the Search Distance functions.
Now when you search for 50 miles or what ever mile distance you should choose, even down to the foot, then the results shown are now all within that search radius.
So now we are back to a true search radius like we had before the recent server side algorithm change.
We recently changed the search distance function. The world is a sphere not a flat surface. So to find the latitude and longitude that is a certain distance from a given point on the sphere (the earth, your position), then we were using Haversine math to find latitudes and longitudes that were a given search distance that the user specified.
The Haversine formulas turned out to put a pretty heavy load onto the server. Imagine how long it took to calculate the latitude and longitude haversine distance for a million records in the database.
So I had a rethink on the distance calculation algorithm.
So I said, ok what is the maximum latitude and longitude from the given map center search point out to the users desired search distance.
Those max points were easy enough to calculate.
So then I asked the server to give me all lats and longs that are less than those max lats and longs.
And voila. The server could sift through that information real fast without having to do any calculations.
But it was not a true circular search radius like we had before. If I putin a 50 mile search distance radius, I might get results showing that were 52 miles away. Rather than try to explain why when a user puts in 50 miles search radius and then gets results showing 52 miles away, I decided it was just easier to fix the issue so that only results that are exactly 50 miles distance or less were shown in the search results making the new distance calculation radius a true circular 50 mile radius search for the end user.
So today, I smoothed out the search results to keep with the new server side search algorithm plus eliminating all results that are outside the search distance specified by the user.
Works pretty good.
So mark that one off the list.
Lead Software Developer, Mapertunity