In the above code, we get the data as the array in a variable after decoding the JSON formatted data coming from the API URL. $distance_arr = json_decode($distance_data) Now let’s see our PHP code to retrieve the JSON data and decode it: $distance_data = file_get_contents('&destinations=&key=') To calculate the distance, select your target location point. Then, tap the Measure Distance feature and enable it. Now, Right-click on your marked location. Tap on your desired location to mark that on the map. You can make the unit imperial just by providing the unit parameter just like in the URL below: &destinations=&key= While using your PC, you may measure distance between two points by following these steps: On your browser open the Google Maps. Get country data by clicking on map – PHP source codeīelow is the given URL structure which sends us the data which contains the distance and the duration to reach: &destinations=&key=īy default, the unit is metric. Get visitors country and city in PHP using Freegeoip API To measure the distance between two points: On your computer, open Google Maps. But here we are going to use the JSON data format which is also recommended by the Google’s API provider. They provide both JSON and XML formatted data. Google allows retrieving the data through the URL. To get the distance we are going to set parameters with an API key to the API URL through the get method. When using Google Maps on a computer, right-click a spot on. But for simplicity and for better understanding we are going to retrieve the distance and time duration between two places only. You can measure distance on Google Maps to give you the approximate mileage between any two points (or more) that you place on the map. Using this API, we can get the distance and duration to reach the destination from the origin for two or multiple origins and destinations. Google’s Distance Matrix API provides you the distance between places. We are going to learn how to work with Google Distance Matrix API in PHP. Here in this post, we are going to introduce with an amazing and interesting trick.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |