需要一些帮助。 所以我使用Google API Snap To Road。 这里是我的代码:从捕捉道路获取结果API
<?php
set_time_limit(0);
$jsonarr = array();
$today=date("Y-m-d");
$ACCOUNT=$_GET['ACCOUNT'];
$ticket_no=$_GET['ticket_no'];
require_once("config/msdb_connect.php");
$query = mssql_query("SELECT * FROM TblGps WHERE DOOR = '".$ticket_no."' AND DATETIME BETWEEN '".$today." 00:00:00' AND '".$today." 23:59:59' ORDER BY DATETIME DESC");
while($row = mssql_fetch_array($query))
{
//parameters
$lng=$row['LONG'];
$lat=$row['LAT'];
//$data = array('lat'=>$lat,'lng'=>$lng);
//echo $latlng = GetArray($data);
$jsonarr[] = array(
'id' => $row['ID'],
'account' => $row['ACCOUNT'],
'datetime' =>date("m/d/Y H:i:s",strtotime($row['DATETIME'])),
'loc' => $row['LOCATION'],
// 'speed' => $row['SPEED'],
'longi' => $lng,
'lat' => $lat,
'lac' => $row['LAC'],
'cid' => $row['CID'],
// 'engine' => $row['ENGINE'],
'remarks' => $row['REMARKS']
);
}
$path = GetArray($jsonarr);
$snailtrail=GetSnailTrail($path);
function GetArray($array){
$stringdata = "";
for($i = 0 ; $i <= count($array) - 1 ; $i++){
$rows = (object)$array[$i];
if($i == count($array) - 1) $stringdata .= $rows->lat.','.$rows->longi;
else $stringdata .= $rows->lat.','.$rows->longi.'|';
}
return $stringdata;
}
function GetSnailTrail($path){
$key='AIzaSyDRlfacNyHn7ZOsC0FzufqZ_rtQYfZD6wA';
$url='https://roads.googleapis.com/v1/snapToRoads?path='.$path.'&interpolate=true&key='.$key.' ';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST,"POST");
// curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$api_response = curl_exec($curl);
curl_close($curl);
$result = json_decode($api_response);
$result = (object)$result;
$result = (object)$result->location;
return $result;
}
所以我从我的DATABSE获取经度和纬度。 然后,我将使用我的函数GetArray将其组合为GetSnailTrail函数中参数路径的多个记录。
因此,这将是这个样子的发送API之前:
https://roads.googleapis.com/v1/snapToRoads?path=14.567467,121.030726|14.566950,121.030497|14.567447,121.031204|14.566947,121.030520|14.566947,121.030520|14.567590,121.031181|14.567590,121.031181|14.567377,121.031236|14.566947,121.030520|14.567447,121.031204|14.566947,121.030520|14.566947,121.030520|14.566947,121.030520|14.566947,121.030520|14.567590,121.031181|14.567377,121.031236|14.567447,121.031204|14.567377,121.031236|14.567377,121.031236|14.567377,121.031236|14.567377,121.031236|14.567377,121.031236|14.567377,121.031236|14.567590,121.031181|14.567377,121.031236|14.567590,121.031181|14.567377,121.031236|14.567447,121.031204|14.567377,121.031236|14.567447,121.031204|14.567377,121.031236|14.567466,121.030726|14.567377,121.031236|14.567377,121.031236|14.567377,121.031236|14.567447,121.031204|14.567377,121.031236|14.567056,121.030569|14.567012,121.030539|14.567049,121.030568|14.567009,121.030545|14.567468,121.030728|14.567031,121.030549|14.567007,121.030545|14.567098,121.030403|14.567037,121.030548|14.567178,121.030624|14.566899,121.030486|14.566946,121.030520|14.567056,121.030569|14.567056,121.030569|14.567056,121.030569|14.566946,121.030520|14.566947,121.030522|14.566947,121.030522|14.566947,121.030522|14.567103,121.030594|14.566946,121.030520|14.566947,121.030522|14.566947,121.030524|14.567028,121.030556|14.566780,121.030502|14.566780,121.030502|14.567103,121.030594|14.567103,121.030594|14.566947,121.030522|14.566946,121.030520|14.566946,121.030520|14.566946,121.030520|14.566947,121.030524|14.566947,121.030524&interpolate=true&key=AIzaSyDRlfacNyHn7ZOsC0FzufqZ_rtQYfZD6wA
后,该API将返回这样的结果:
{
"snappedPoints": [
{
"location": {
"latitude": 14.567361300000002,
"longitude": 121.03068420000001
},
"originalIndex": 0,
"placeId": "ChIJF6oagKzJlzMRlFWOLr4F1SI"
}
出于某种原因,我不能呼应或获得在我的$jsonarr
上输入它的响应。 得到回应后该怎么办? 谢谢
卷曲没有提供任何错误?请参阅:[curl_error](http://php.net/manual/en/function.curl-error.php)。和'var_dump($ api_response)'。 – Jigar
是的,它显示411错误 –