0
몇 시간을 들여다 보았지만 왜 JSON 쿼리가 구문 분석하려고하는 CSV/TXT 파일의 마지막 줄에 대한 결과 만 반환하는지 이해할 수 없지만. 여기 CSV를 반복하고 각 결과를 사용하여 JSON 쿼리를 구문 분석
코드입니다 : 다른 사람의 아무도 돌아 오지 (가) '4066'는 RG12 0GD의 우편 번호에 대한 올바른 변수Distance by Post Code Generator v0.1 by Phil Hughes
RG12 0GA
RG12 0GB
RG12 0GC
RG12 0GD4066
하지만 :
//Enter API Key Here
$api_key = 'AIzaSyB9Dq3w1HCxkS5qyELI_pZuTmdK8itOBHo';
$origin = 'RG12 1AA';
$output_type = 'json'; //xml or json
$csv_location = 'http://www.naturedock.co.uk/postcodes.csv';
//Do not edit
$base_url = 'https://maps.googleapis.com/maps/api/directions/';
$origin_url = '?origin=';
$destination_url = '&destination=';
$end_url = '&sensor=false&key=';
$page = join("",file("$csv_location"));
$kw = explode("\n", $page);
for($i=0;$i<count($kw);$i++){
$destination = $kw[$i];
echo $destination;
$raw_url = $base_url . $output_type . $origin_url . $origin . $destination_url . $destination . $end_url . $api_key;
$request_url = str_replace(' ', '', $raw_url);
$getJson = file_get_contents($request_url);
$routes = json_decode($getJson);
$result = $routes->routes[0]->legs[0]->distance->value;
echo $result . '<br>';
}
내가 얻을 결과이 같은 모습 당신이 볼 수있는 결과.
도와주세요. 귀하의
join("",file("$csv_location"));