dsa1234569 2015-10-10 09:47
浏览 34
已采纳

PHP函数不返回值

I am trying to fetch some data from google API and have called API for interval when I am printing my result into the function above return I am getting result but not getting actual location (first code). I am unable to understand why this is.

  $cSession = curl_init();
          //step2
          curl_setopt($cSession,CURLOPT_URL,"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$latitude&radius=500&key=My_key);
          curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
          curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);

          //step3
          $result=curl_exec($cSession);
          $abc=curl_error($cSession);
          //step4
          curl_close($cSession);

          $res=json_decode($result);
//           echo '<pre>';
//           print_r($res);exit;
          $place_array[]=$res->results;
          $result1=array();
          if(isset($res->next_page_token) && $res->next_page_token!=''){
            $result1=$this->getPageNext($res->next_page_token,$place_array,$latitude);
          }
          else{
            $result1=$place_array;
          }

My function is:

            public function getPageNext($next_page_url,$place_array,$latitude){

            error_reporting(E_ALL);

            sleep(2);
            $cSession = curl_init();

            //step2
            curl_setopt($cSession,CURLOPT_URL,"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$latitude&radius=500&key=AIzaSyBgEtE4_8jNbVrC356EXr53NihsB-clR2k&pagetoken=$next_page_url");
            curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
            curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);

            //step3
            $result=curl_exec($cSession);
            $abc=curl_error($cSession);
            //step4
            curl_close($cSession);
//              echo '<hr>';
//              echo "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$latitude&radius=500&&key=mykey-clR2k&pagetoken=$next_page_url";
//              echo '<br>';
            $res=json_decode($result);
//              exit;
            $place_array[]=$res->results;
            if(isset($res->next_page_token) && $res->next_page_token!=''){
//                  echo 1;
                $this->getPageNext($res->next_page_token,$place_array,$latitude);
            }
            else{
//                  echo '<pre>';
//                  print_r($place_array);exit;
                return json_encode($place_array);exit;
            }

        }

展开全部

  • 写回答

1条回答 默认 最新

  • dsjlqkbpn029473708 2018-04-08 22:13
    关注

    Resolve this by getting error from curl_error

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部