![]() ![]() 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=') You can make the unit imperial just by providing the unit parameter just like in the URL below: &destinations=&key= Then touch and hold on to a place from where you want to start measuring the distance. 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 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. For example, if the distance was three miles and the time taken was 2 minutes, then the average speed across that distance would be 90mph. Calculate the average speed based on these results. Google allows retrieving the data through the URL. Determine the difference between the two timestamps to calculate how long it took to get from Point A to Point B. To get the distance we are going to set parameters with an API key to the API URL through the get method. But for simplicity and for better understanding we are going to retrieve the distance and time duration between two places only. ![]() 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. |