dsa1234569 2015-10-10 17: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-09 06:13
    关注

    Resolve this by getting error from curl_error

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

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services