2017-12-20 18 views
0

google places API를 호출하고 JSON 데이터를 반환하는 메소드를 호출하고 있습니다. json 데이터를 반복해야합니다. URL을 호출하거나 리디렉션을 사용하려면 CURL 요청을 사용해야합니까?Google지도에서 반복 수행 laravel의 JSON 데이터

public function getPlaces(Request $request) { 

     $latitude = $request->latitude; 
     $longitude = $request->longitude; 
     $radius = $request->radius; 
     $service_type = $request->service_type; 
     $api_key = env("API_KEY"); 

     $toSend = Redirect::to("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$latitude,$longitude&radius=$radius&type=$service_type&key=$api_key"); 


     $arr = []; 
     $data = []; 
     $data = json_decode($toSend); 

     foreach($data as $v) { 

      //perform operation 
     } 

     return something; 

    } 
+0

내가 DD ($ toSend)를 볼 수 있습니까? –

+0

$ 데이터가 배열을 반환하지 않습니다 –

+0

@EtibarRustemzade 저는 우체부를 사용하여 API로 개발 중입니다. 브라우저에서 정상적으로 처리하면 정상적으로 작동합니다. –

답변

1

리디렉션을 사용하지 마십시오. HTTP를 사용하여 브라우저를 리디렉션하려고 시도합니다. Guzzle과 같은 라이브러리를 사용하여 서버에서 Google로 편안한 GET 요청을합니다.


$client = new GuzzleHttp\Client(); 

$res = $client->get('put your url here'); 

if($res->getStatusCode() == 200){ 

    $toSend = $res->getBody(); 


}