如何找到最佳的仓库位置?

I have the following problem to solve. There are several warehouses across the US we want to ship products from. Lets assume the products are always in stock at these warehouses. When someone places an order, I want to select the best warehouse to ship from to minimize shipping costs and time in transit.

What would be a good solution to automatically measure the distances between the possible warehouses and the shipping address and select the nearest warehouse to the customer? I am looking towards a more theoretic answer but if it helps, the target platform is a PHP + MySQL based online shop.

Because you are travelling by road, you cannot simply use an algorithm to calculate the straight distance of two GPS points.

You can create a database of distances manually if you send large quantities to a limited amount of destinations.

If these are small quantities going to very many destinations, use the Google Maps API or check out OpenStreetMap for something similar.

one option - find a service that has geo-locations for each zip code. then use a haversine or great circle distance calculation to see which place is closer.

another option - brute force. create a table that links warehouse to destination zip code - then populate it and just query for the right warehouse. i might prefer this because the cost of shipment may not be a simple distance calculation.