简体   繁体   中英

Google Maps Javascript API Distance Matrix Request Limitations

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM