Below is PHP code:
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
function
distance(
$lat1
,
$lng1
,
$lat2
,
$lng2
)
{
$url = " http://maps.google.com/maps/api/directions/xml?origin= " . $lat1 . " , " . $lng1 . " &destination= " . $lat2 . " , " . $lng2 . " &sensor=false " ;
$tem = simplexml_load_file ( $url );
$tem -> registerXPathNamespace( " tem " , " http://www.w3.org/2005/Atom " );
$rs = 0 ;
for ( $i = 0 ; $i < count ( $tem -> route -> leg -> step); $i ++ )
{
$rs += $tem -> route -> leg -> step[ $i ] -> distance -> value;
}
return $rs ;
}
{
$url = " http://maps.google.com/maps/api/directions/xml?origin= " . $lat1 . " , " . $lng1 . " &destination= " . $lat2 . " , " . $lng2 . " &sensor=false " ;
$tem = simplexml_load_file ( $url );
$tem -> registerXPathNamespace( " tem " , " http://www.w3.org/2005/Atom " );
$rs = 0 ;
for ( $i = 0 ; $i < count ( $tem -> route -> leg -> step); $i ++ )
{
$rs += $tem -> route -> leg -> step[ $i ] -> distance -> value;
}
return $rs ;
}