Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 谷歌地理编码API只适用于一个单词地址_Php_Geocoding_File Get Contents_Google Geocoding Api - Fatal编程技术网

Php 谷歌地理编码API只适用于一个单词地址

Php 谷歌地理编码API只适用于一个单词地址,php,geocoding,file-get-contents,google-geocoding-api,Php,Geocoding,File Get Contents,Google Geocoding Api,如果我只使用一个词,比如 悉尼 但如果我使用: 澳大利亚悉尼 它不起作用,它说: 警告: 文件获取内容(, 澳大利亚&sensor=false):无法打开流:HTTP请求失败! HTTP/1.0 400错误请求 即使当我粘贴此url时,它在我的浏览器中工作,但当我使用此功能时,file\u get\u contents它不工作 我的问题很简单,为什么粘贴这个结果时它会在我的浏览器中工作,为什么它不能与下面的代码一起工作。当然还有如何解决这个问题 $a = file_get_contents("h

如果我只使用一个词,比如

悉尼

但如果我使用:

澳大利亚悉尼

它不起作用,它说:

警告: 文件获取内容(, 澳大利亚&sensor=false):无法打开流:HTTP请求失败! HTTP/1.0 400错误请求

即使当我粘贴此url时,它在我的浏览器中工作,但当我使用此功能时,
file\u get\u contents
它不工作

我的问题很简单,为什么粘贴这个结果时它会在我的浏览器中工作,为什么它不能与下面的代码一起工作。当然还有如何解决这个问题

$a = file_get_contents("https://maps.google.com/maps/api/geocode/json?address=sydney, Australia&sensor=false");

您必须对地址进行url编码:

$a = file_get_contents("https://maps.google.com/maps/api/geocode/json?address=" . urlencode('sydney, Australia') . "&sensor=false");

您必须对地址进行url编码:

$a = file_get_contents("https://maps.google.com/maps/api/geocode/json?address=" . urlencode('sydney, Australia') . "&sensor=false");

是空间造成了这里的问题。人们正在使用:

$address = str_replace(' ','+',$address);

注:这是一个迟来的回复,但可能会帮助一些通过搜索到达页面的其他人,如我。

这是造成问题的空间。人们正在使用:

$address = str_replace(' ','+',$address);
另外,这是一个迟来的回复,但可能会帮助一些通过搜索到达页面的其他人,比如我。

$address=urldecode($person\u basic->address)
$a=文件获取内容(“https://maps.google.com/maps/api/geocode/json?address=“$address.”传感器=false“仍不工作…
$address=urldecode($person\u basic->address)
$a=文件获取内容(“https://maps.google.com/maps/api/geocode/json?address=“$address.”传感器=false“仍不工作。。。