I made a distance calculator between zipcodes in the US that utilizes the google distance matrix api and I figured out how to get it work for just about all locations but places like Key West FL zip code 33040 do not seem to work.
At first many places weren't working, but then I added "US" to the parameters and it fixed the problem for the most part, besides the one mentioned.
var button= document.getElementById('submit');
button.onclick = function initMap() {
var origin = '07675';
var temp = document.getElementById('address').value;
var destination = temp + ' US';
var geocoder = new google.maps.Geocoder;
var service = new google.maps.DistanceMatrixService;
service.getDistanceMatrix({
origins: [origin],
destinations: [destination],
travelMode: 'DRIVING',
unitSystem: google.maps.UnitSystem.IMPERIAL,
avoidHighways: false,
avoidTolls: false
}, function(response, status) {
if (status !== 'OK') {
alert('Error was: ' + status);
} else {
var originList = response.originAddresses;
var destinationList = response.destinationAddresses;
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = '';
var results = response.rows[0].elements;
var numbah = ((results[0].distance.value * .15 / 1609) + 400);
var nums = numbah.toFixed(2);
geocoder.geocode({'address': originList[0]});
geocoder.geocode({'address': destinationList[0]});
outputDiv.innerHTML += originList[0] + ' to ' + destinationList[0] +
':<br>' + results[0].distance.text + '<br>The cost of shipping is estimated to be: $' + nums;
}
The expected output should be the distance from the origin and the calculated shipping cost, and it works for just about any zipcode besides obscure ones like the one I mentioned earlier.