Using Google Maps API, I'm attempting to get the driving distance between two points. I now have a function that calculates direct distance:

This function get lat and lng:

```function get_coordinates(\$city, \$street, \$province)
{
\$ch = curl_init();
curl_setopt(\$ch, CURLOPT_URL, \$url);
curl_setopt(\$ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(\$ch, CURLOPT_PROXYPORT, 3128);
curl_setopt(\$ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt(\$ch, CURLOPT_SSL_VERIFYPEER, 0);
\$response = curl_exec(\$ch);
curl_close(\$ch);
\$response_a = json_decode(\$response);
\$return = array('lat' => \$response_a->results->geometry->location->lat, 'long' => \$long = \$response_a->results->geometry->location->lng);

return \$return;
}
```

This function calculates distance between two points based on lat & lng:

```function getDistanceBetweenPoints(\$lat1, \$lon1, \$lat2, \$lon2) {
\$theta = \$lon1 - \$lon2;
\$miles = acos(\$miles);
\$miles = \$miles * 60 * 1.1515;
\$kilometers = \$miles * 1.609344;
return \$kilometers;
}
```

This function prints distance by kilometers:

```function get_distance(\$lat1, \$lat2, \$long1, \$long2)
{
/* These are two points in New York City */
\$point1 = array('lat' => \$lat1, 'long' => \$long1);
\$point2 = array('lat' => \$lat2, 'long' => \$long2);

\$distance = getDistanceBetweenPoints(\$point1['lat'], \$point1['long'], \$point2['lat'], \$point2['long']);
return \$distance;
}
```

Usage:

```\$coordinates1 = get_coordinates('Katowice', 'Korfantego', 'Katowicki');
\$coordinates2 = get_coordinates('Tychy', 'Jana Pawła II', 'Tyski');

echo 'Distance: <b>'.round(get_distance(\$coordinates1['lat'], \$coordinates2['lat'], \$coordinates1['long'], \$coordinates2['long']), 1).'</b> km';```

However, this code obtains a direct distance. I require a travel distance. How can I use the Google Maps API to get the driving distance? Jul 31 in PHP 7 views

## How to calculate the difference between two dates using PHP?

I have two dates on the form: Start ...READ MORE

Hii @kartik, If you want the biggest image ...READ MORE

## How to get the Last Inserted Id Using Laravel Eloquent?

Hello @kartik, Firstly create an object, Then set ...READ MORE

## How to get a list of user accounts using the command line in MySQL?

Hello @kartik, Use this query: SELECT User FROM mysql.user; Which ...READ MORE

## How to get name of current directory using php?

Hello @kartik, To get only the name of ...READ MORE

+1 vote

## Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

## How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE