[html] PHP使用Google map web services来计算两点间的距离 -- Compute the distance between two place via Google map services in PHP

Below is PHP code:

 

代码
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;
}

 

posted @ 2010-06-01 18:39  DavidHHuan  阅读(632)  评论(0编辑  收藏  举报