dongxi3209
dongxi3209
2015-11-04 11:23
浏览 36

Php,谷歌距离矩阵总是返回false

here is the link what Im trying with:

https://maps.googleapis.com/maps/api/distancematrix/json?origins=47.02842388681676|18.51792812347412&destinations=47.4735911253571|20.596618652343803&key=*******&language=en&units=metric

this works great from browsers. But gives FALSE from php:

  $ch = curl_init();
  $url = 'https://maps.googleapis.com/maps/api/distancematrix/json?origins='.urlencode($lat1).'|'.urlencode($long1).'&destinations='.urlencode($lat2).'|'.urlencode($long2).'&key='.urlencode('**********').'&language=en&units=metric';
  echo $url;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $c = curl_exec($ch);
  curl_close($ch);
  //$c = json_decode($c);
  echo '<pre>'; var_dump ($c);die;
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutale7115
    doutale7115 2015-11-04 11:36
    已采纳

    You can try with file_get_contents:

    $content = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?origins=47.02842388681676|18.51792812347412&destinations=47.4735911253571|20.596618652343803&key=*******&language=en&units=metric');
    $content = json_decode($content);
    
    print_r($content);
    
    点赞 评论

相关推荐