【发布时间】:2019-04-05 00:09:45
【问题描述】:
我试图从 google geocoding api 获取 json 数据。但是 php 警告显示一些关于“加载 cafile 流失败”的错误
这是我的代码:
$apiKey = 'apikey';
$address = urlencode( '1600 Amphitheatre Pkwy, Mountain View, CA 94043'
);
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=
{$address}key={apiKey}";
$resp = json_decode( file_get_contents( $url ), true );
echo $url;
$lat = $resp['results'][0]['geometry']['location']['lat'] ?? '';
$long = $resp['results'][0]['geometry']['location']['lng'] ?? '';
这是错误:
PHP Warning: failed loading cafile stream: `C:\xampp\apache\bin\curl-ca-
bundle.crt' in C:\Users\1\Desktop\test.php on line 7
Warning: failed loading cafile stream: `C:\xampp\apache\bin\curl-ca-
bundle.crt' in C:\Users\1\Desktop\test.php on line 7
PHP Warning: file_get_contents(): Failed to enable crypto in
C:\Users\1\Desktop\test.php on line 7
Warning: file_get_contents(): Failed to enable crypto in
C:\Users\1\Desktop\test.php on line 7
PHP Warning:
file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy%2C+Mountain+Vi
ew%2C+CA+94043key={apiKey}): failed to open stream: operation failed in
C:\Users\1\Desktop\test.php on line 7
Warning:
file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy%2C+Mountain+View%2C
+CA+94043key={apiKey}): failed to open stream: operation failed in
C:\Users\1\Desktop\test.php on line 7
https://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy%2C+Mountain+View%2C+CA+94043key={apiKey}
【问题讨论】: