I'm working on an estimate rate calculator. You enter in two zip codes and multiply a distance by a rate. e.g., 100 miles by 25 cents I'm using the Distance Matrix Service API by Google to get the distance.
You can use a URL like
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=44039&destinations=75081&key=your_api_key and it will return
You can take the distance and do your math. A problem I was running into was when I used the zip code
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=44039&destinations=16508&key=your_api_hey The address for that was missing
Well, that doesn't work. In doing some testing, I mashed in a four digit zip code and got results back. I noticed the four-digit zip had a complete address. How can I ensure I look for zip codes? I dug deeper into the documentation since searching the web didn't turn up anything. I saw a mention about
place_id, and you can use
origins=place_id:ChIJ3S-JXmauEmsRUcIaWtf4MzE. I thought "Can I use zip?"
It works. Now I can get distances to Erie, PA.
I hope this helps.