duanbing2963 2011-12-13 15:46
浏览 59
已采纳

PHP中不同的响应地理编码直接在URL导航栏中进行(Google maps api v3 json)

If I put this URL: http://maps.googleapis.com/maps/api/geocode/json?address=la%20coru%C3%B1a,%20la%20coru%C3%B1a,%20espa%C3%B1a&sensor=false&region=es

I get this json object:

{   "results" : [
  {
     "address_components" : [
        {
           "long_name" : "A Coruña",
           "short_name" : "A Coruña",
           "types" : [ "locality", "political" ]
        }, etc...

But if I try it with PHP:

<?php $address = urlencode("la coruña, la coruña, España"); $geocode = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.$address.'&sensor=false&region=es'); echo "<pre>"; print_r($geocode); echo "</pre>";?>

The response is not equal.

You can see that it's not equal: Corunna != Coruña

I have been dealing with UTF-8 but I don't get a solution.

  • 写回答

1条回答 默认 最新

  • drd43058 2011-12-14 13:53
    关注

    You specify the region, but that causes region biasing, but doesn't affect the output language. For that, you need to specify the language parameter. From the API docs:

    • language (optional) — If language is not supplied, the geocoder will attempt to use the native language of the domain from which the request is sent wherever possible.

    I would guess that the server that runs the PHP code is in a different country than you are (or Google thinks it is). That's why you get different results when requesting from the server and requesting from your browser.

    In fact, when I click on the url you provide, I get the english version ("Corunna") output, presumably because I am in the United States. If I add &language=es to the url I get the spanish version ("A Coruña").

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

报告相同问题?

悬赏问题

  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题