Reputation: 129
The distance matrix request in Google Maps API is limited to 25 destinations. I want to be able to get my current location using geolocation and find the closest train station based on a database of train station addresses that I have compiled. My problem is that my database might contain 100+ train stations, so I need to split up my one big distance matrix request into multiple small ones. When Google Maps API returns the result, it normalizes the format of the address, which makes it difficult to programmatically pair the response with the original database row based on the address string. Also, these are asynchronous requests, which means that the responses could come in any order. Is there some way of passing an index to the callback function, so that I can pair the responses with the requests? What is the best method of handling this?
Upvotes: 3
Views: 1114
Reputation: 7228
If you store the lat/lng coordinates in your database you can use the Haversine Formula to find the nearest station. This DEMO uses this technique. The database was derived from data obtained from Geonames
Upvotes: 2
Reputation: 161334
Do an initial cut of train stations by using the straight line distance (which can be computed directly from the geographic coordinates, using the haversine formula). Only send the 25 closest stations to the distance matrix.
Upvotes: 2