In this article, you are going to learn how you can find the distance between two addresses. We are going to use google map API and PHP to accomplish this task.
The distance calculator module we are going to develop here is basically an API provided by Google itself. This API can measure the driving distance between two addresses as well as Travel Time. You can also measure distance between cities using this module.
The format for origin location and destination location could be one of the following:
- place name (e.g. Bhopal, India)
- ZIP code (e.g. 462016)
- latitude/longitude coordinates (e.g. 23.77xxx, 77.30xxx)
to know more about permissible formats please visit Google’s official documentation page.
Find Distance Between two Addresses
Step 1:- Get a google’s API Key from https://developers.google.com/maps/documentation/distance-matrix/get-api-key.
click on GET A KEY button
now click on +create a new project and enter your project name then click on ENABLE API button
then after you are finally prompted to a popup window containing your API KEY.
Step 2: source code
see the demo here
rows->elements->distance->value / 1000).' Km'; ?>
replace YOUR_API_KEY with your API KEY (Step 1) in above code.
We have covered find distance between two addresses module in this article, to get latest updates please subscribe our blog and follow us on Facebook. Don’t forget to share this article with your friends.
You may also like
- Get Users Latitude and Longitude using Google Place API and PHP
- Autocomplete Address Search Module Using Google API and PHP
- Track User’s Real IP Address
The post Find The Distance Between two Addresses using Google API and PHP appeared first on My Programming Tutorials.