Reputation: 1
I have made a web page but I need an instant quote form or box that asks visitors for zip codes or addresses and we give back a quote for shipping. I need the distance to be multiplied by the rate per mile. Every thing I have tried has been straight line not driving. Does anyone know how to find driving distance between two zip codes or address both?
Upvotes: 0
Views: 697
Reputation: 53861
You can use the google maps api.
Do a call
http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false
Parse the json output with json_decode()
Iterate each leg of the journey adding up the distance
in miles.
This will give you the driving distance between two addresses. It will always be longer than a straight line, but it is accurate nonetheless.
If straight line distance between addresses is needed, you can use the API pull the latitude and longitude for each address, then use this cacluation to determine the distance in miles or kilometers.
Upvotes: 3