At the moment I have a web app that uses Google Maps APIs to get distance between one location (store) and a list of other locations (techs), as its all cached in a DB, it only has to run once. But its very slow that first time….
What im needing to do now is make a front end for customers, where they can enter in their address and find the closest store. As there is a tone of stores, trying to get addresses of each store and comparing it with the customers address using Google Maps API is going to take forever.
So what techniques are available to make this faster? Is it possible to filter out most of the addresses with the difference of lat and long? Or is their an API method that I can give Google Maps with a long list of addresses and have it return the closest address?
What you’re supposed to do is when adding the stores to the database also include their lat/lngs. This way when the user enters their address, you just need to geocode their address(get the lat/lng), and use the haversine formula (which is just math so it runs fast) to get the closest locations.
https://developers.google.com/maps/articles/phpsqlsearch_v3
You can use the google geocoding api to get/insert the lat/lng of the stores already in your database.
I currently have a locator that searches tens of thousands of stores and it executes in under a second using this method.