Reputation:
I have a database table filled with addresses, the table is over 4,000 records long
I am wondering the best way to get the addresses compare it with a search field and sort them by distance from the search field location? GoogleAPI documentation says the requests are limited to like 25,000 per day does that mean I can only do 7 searches per day?
Upvotes: 0
Views: 84
Reputation: 7572
In my opinion - yes. Google is smart about calculating distance between 2 LatLng's, because gives you distance using streets and roads, not distance in a straight line between 2 points (which would be easy to calculate in php).
Saving LatLng's of those 4000 addresses wouldn't do you any good, because you still need to ask google about the distance from a user's address to each of them. You can't calculate that yourself even if you have all the LatLng's (you need the map).
I guess you could save each user input, and save that address with 4000 distances to each location... but that would only be useful for a user returning to the site for the 2nd time.
...
Ok, I have this idea:
This way you'd get the first 10-20 accurate distances to the closest locations from user input, and the rest would be pulled from the database - they would actually be distances from the closest location to the other locations.
Upvotes: 1
Reputation: 4887
I believe that since the addresses don't change that much, you can cache the latitude/longitude somewhere and refer to those instead of making repeated requests. Please elaborate if there are other mitigating conditions, of course.
Upvotes: 0