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

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

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来