【问题标题】:Google API Geocoding谷歌 API 地理编码
【发布时间】:2014-05-25 18:05:32
【问题描述】:

我对使用 PHP 的 google maps api 有疑问。我使用file_get_contents 函数向google 发出get 请求,它的工作正常。但是,如果我对带有重音字母的城市提出 get 请求,它就不起作用并返回给我 INVALID_REQUEST。我的例子是:

第一个不起作用,第二个与 file_get_contents 完美配合。如果我对 url 进行编码不起作用,请使用 urlencode。 另一件事是,如果我在浏览器中剪切并粘贴第一个 url,它就可以工作!所以这不是谷歌的问题,但我对来自 php 的 get 调用的编码有误。任何人都可以帮助我吗?

非常感谢。

【问题讨论】:

标签: php json google-maps google-maps-api-3 google-geocoding-api


【解决方案1】:

你试过rawurlencode吗?

file_get_contents( rawurlencode( $url ) );

【讨论】:

  • Google 想要在 utf-8 中编码的字符串,在 urlencode 之前我必须对城市进行 utf8 编码。不过谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-28
  • 1970-01-01
  • 2011-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多