【发布时间】:2017-01-24 11:55:42
【问题描述】:
我的 php 代码使用位置编号返回 $distance 值,但如何使用位置名称获取距离?
这里代码
$from = "Arlington Heights, IL 60005, United States";
$to = 'Arlington Heights, IL 60004, United States';
$from = urlencode($from);
$to = urlencode($to);
$data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false");
$data = json_decode($data);
$time = 0;
$distance = 0;
foreach($data->rows[0]->elements as $road) {
$time += $road->duration->value;
$distance += $road->distance->value;
}
【问题讨论】:
-
“位置编号”是什么意思?据我所知,您在代码中使用了实际的地名?