Distance between two addresses using Google Maps in PHP

6

We can easily calculate distance between two addresses using Google Maps API and PHP. We have created a simple PHP function for getting distance between two addresses. getDistance() function grouped all functionalities together and it accepts three parameters.

  • $addressFrom – Required. Pass the from address.
  • $addressTo – Required. Pass the to address.
  • $unit – Optional. Pass the first letter of desire unit. Default is Mile. ( K – kilometre, N – Nautical Mile)

getDistance() function is given below.

You can use this function like the below.

To specify a Google API key in your request, include it as the value of a key parameter.

 

Leave A Reply

Your email address will not be published.