2

我正在使用Google 的GeoCoding API。

我想始终获取英语数据而不是区域语言数据。

我正在调用此API链接,并从以下数据的印地语中键的第一个位置获取formatted_address= लासुरगाव रोड, लसुर, महाराष्ट्र 423702, India :results

{
   "plus_code" : {
      "compound_code" : "W2H6+3M Harsul, Maharashtra, India",
      "global_code" : "7JFQW2H6+3M"
   },
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "लासुरगाव रोड",
               "short_name" : "लासुरगाव रोड",
               "types" : [ "route" ]
            },
            {
               "long_name" : "लसुर",
               "short_name" : "लसुर",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "औरंगाबाद",
               "short_name" : "औरंगाबाद",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "महाराष्ट्र",
               "short_name" : "MH",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "423702",
               "short_name" : "423702",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "लासुरगाव रोड, लसुर, महाराष्ट्र 423702, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 19.9279766,
                  "lng" : 75.011798
               },
               "southwest" : {
                  "lat" : 19.9276098,
                  "lng" : 75.0108685
               }
            },
            "location" : {
               "lat" : 19.9277932,
               "lng" : 75.01133329999999
            },
            "location_type" : "GEOMETRIC_CENTER",
            "viewport" : {
               "northeast" : {
                  "lat" : 19.9291421802915,
                  "lng" : 75.0126822302915
               },
               "southwest" : {
                  "lat" : 19.9264442197085,
                  "lng" : 75.0099842697085
               }
            }
         },
         "place_id" : "ChIJRS92AquJ2zsRGIY8TmId5OQ",
         "types" : [ "route" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Lasur",
               "short_name" : "Lasur",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Aurangabad",
               "short_name" : "Aurangabad",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Maharashtra",
               "short_name" : "MH",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "423702",
               "short_name" : "423702",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Lasur, Maharashtra 423702, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 19.9365397,
                  "lng" : 75.0198626
               },
               "southwest" : {
                  "lat" : 19.9104756,
                  "lng" : 74.99952089999999
               }
            },
            "location" : {
               "lat" : 19.9282261,
               "lng" : 75.0114612
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 19.9365397,
                  "lng" : 75.0198626
               },
               "southwest" : {
                  "lat" : 19.9104756,
                  "lng" : 74.99952089999999
               }
            }
         },
         "place_id" : "ChIJqakxlFSI2zsRU2QZ0WNgCMQ",
         "types" : [ "locality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "423702",
               "short_name" : "423702",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Aurangabad",
               "short_name" : "Aurangabad",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Maharashtra",
               "short_name" : "MH",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Maharashtra 423702, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 19.9812906,
                  "lng" : 75.14881470000002
               },
               "southwest" : {
                  "lat" : 19.7257081,
                  "lng" : 74.7853344
               }
            },
            "location" : {
               "lat" : 19.8539262,
               "lng" : 74.9910112
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 19.9812906,
                  "lng" : 75.14881470000002
               },
               "southwest" : {
                  "lat" : 19.7257081,
                  "lng" : 74.7853344
               }
            }
         },
         "place_id" : "ChIJAVBUmAp43DsRAohUV0LQMO4",
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Aurangabad",
               "short_name" : "Aurangabad",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Maharashtra",
               "short_name" : "MH",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Aurangabad, Maharashtra, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 20.6673799,
                  "lng" : 76.04805
               },
               "southwest" : {
                  "lat" : 19.37426,
                  "lng" : 74.58680009999999
               }
            },
            "location" : {
               "lat" : 19.8910826,
               "lng" : 75.1545381
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 20.6673799,
                  "lng" : 76.04805
               },
               "southwest" : {
                  "lat" : 19.37426,
                  "lng" : 74.58680009999999
               }
            }
         },
         "place_id" : "ChIJOV9BNoai2zsRtocWKbhGxs8",
         "types" : [ "administrative_area_level_2", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Maharashtra",
               "short_name" : "MH",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Maharashtra, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 22.028441,
                  "lng" : 80.890924
               },
               "southwest" : {
                  "lat" : 15.6024121,
                  "lng" : 72.659363
               }
            },
            "location" : {
               "lat" : 19.7514798,
               "lng" : 75.7138884
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 22.028441,
                  "lng" : 80.890924
               },
               "southwest" : {
                  "lat" : 15.6024121,
                  "lng" : 72.659363
               }
            }
         },
         "place_id" : "ChIJ-dacnB7EzzsRtk_gS5IiLxs",
         "types" : [ "administrative_area_level_1", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.513327,
                  "lng" : 97.39535869999999
               },
               "southwest" : {
                  "lat" : 6.4626999,
                  "lng" : 68.1097
               }
            },
            "location" : {
               "lat" : 20.593684,
               "lng" : 78.96288
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.513327,
                  "lng" : 97.39535869999999
               },
               "southwest" : {
                  "lat" : 6.4626999,
                  "lng" : 68.1097
               }
            }
         },
         "place_id" : "ChIJkbeSa_BfYzARphNChaFPjNc",
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}

是否可以English只获取每次数据,因为我不想要区域语言的数据?

编辑:

我最近尝试了什么?

  • 通过Accept-Language=enAccept-Language=en-US在标头中但不工作。
  • 尝试过language=enhl=en不工作。
4

2 回答 2

1

我相信这可能是一种预期的行为。如果地址本地语言与用户语言具有相同的字母表,Google 在地理编码 API 响应中偏爱本地语言。

以下博客文章中解释了此行为

https://mapsplatform.googleblog.com/2014/11/localization-of-street-addresses-in.html

如果本地语言和用户语言都使用相同的字母表,则地理编码 API 现在将返回街道和地区的本地名称。例如,在巴西搜索用户语言设置为英语的地址现在返回“Avenida Paulista”而不是“Paulista Avenue”。

如果本地语言和用户语言使用不同的字母,Geocoding API 将返回本地名称,音译为拉丁字母。在某些情况下,可能会返回英文翻译,例如,如果没有音译可用。例如,在用户语言设置为日语的情况下搜索 El Tahrir Square 现在会返回“El-Tahrir Square, Ismailia, Qasr an Nile, Cairo Governorate, エジプト”,而不是“エジプト カイロ県 Qasr an Nile, タハリール広场”(旧结果) 或“ميدان التحرير، قصر النيل، محافظة القاهرة، مصر”(当地名称)。

也许 Google 检测到您的 IP 地址位于印度,因此响应偏爱当地语言。

就我而言,当我从我在西班牙的位置执行您的示例请求时,我会收到以下英文回复

https://maps.googleapis.com/maps/api/geocode/json?latlng=22.9997%2C72.6354&key=MY_API_KEY

{
  "plus_code":{
    "compound_code":"XJXP+V5 Ahmedabad, Gujarat, India","global_code":"7JJJXJXP+V5"
  },
  "results":[
    {
      "address_components":[
        {
          "long_name":"BRTS Corridor",
          "short_name":"BRTS Corridor",
          "types":[
            "route"
          ]
        },
        {
          "long_name":"Rabari Colony",
          "short_name":"Rabari Colony",
          "types":[
            "political","sublocality","sublocality_level_2"
          ]
        },
        {
          "long_name":"Amraiwadi",
          "short_name":"Amraiwadi",
          "types":[
            "political","sublocality","sublocality_level_1"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "locality","political"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "administrative_area_level_2","political"
          ]
        },
        {
          "long_name":"Gujarat",
          "short_name":"GJ",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"India",
          "short_name":"IN",
          "types":[
            "country","political"
          ]
        },
        {
          "long_name":"380008",
          "short_name":"380008",
          "types":[
            "postal_code"
          ]
        }
      ],
      "formatted_address":"BRTS Corridor, Rabari Colony, Amraiwadi, Ahmedabad, Gujarat 380008, India",
      "geometry":{
        "bounds":{
          "northeast":{
            "lat":23.0048831,"lng":72.63708439999999
          },
          "southwest":{
            "lat":22.9996702,"lng":72.6353833
          }
        },
        "location":{
          "lat":23.0022759,"lng":72.6362362
        },
        "location_type":"GEOMETRIC_CENTER",
        "viewport":{
          "northeast":{
            "lat":23.0048831,"lng":72.6375828302915
          },
          "southwest":{
            "lat":22.9996702,"lng":72.6348848697085
          }
        }
      },
      "place_id":"ChIJ9UjW5mqGXjkR2mRics2aU4I",
      "types":[
        "route"
      ]
    },
    {
      "address_components":[
        {
          "long_name":"Rabari Colony",
          "short_name":"Rabari Colony",
          "types":[
            "political","sublocality","sublocality_level_2"
          ]
        },
        {
          "long_name":"Amraiwadi",
          "short_name":"Amraiwadi",
          "types":[
            "political","sublocality","sublocality_level_1"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "locality","political"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "administrative_area_level_2","political"
          ]
        },
        {
          "long_name":"Gujarat",
          "short_name":"GJ",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"India",
          "short_name":"IN",
          "types":[
            "country","political"
          ]
        },
        {
          "long_name":"380038",
          "short_name":"380038",
          "types":[
            "postal_code"
          ]
        }
      ],
      "formatted_address":"Rabari Colony, Amraiwadi, Ahmedabad, Gujarat 380038, India",
      "geometry":{
        "bounds":{
          "northeast":{
            "lat":23.009061,"lng":72.6454679
          },
          "southwest":{
            "lat":22.9931311,"lng":72.6254739
          }
        },
        "location":{
          "lat":23.0019153,"lng":72.6343352
        },
        "location_type":"APPROXIMATE",
        "viewport":{
          "northeast":{
            "lat":23.009061,"lng":72.6454679
          },
          "southwest":{
            "lat":22.9931311,"lng":72.6254739
          }
        }
      },
      "place_id":"ChIJaY70lGuGXjkRp_Y5g5vavs4",
      "types":[
        "political","sublocality","sublocality_level_2"
      ]
    },
    {
      "address_components":[
        {
          "long_name":"380026",
          "short_name":"380026",
          "types":[
            "postal_code"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "locality","political"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "administrative_area_level_2","political"
          ]
        },
        {
          "long_name":"Gujarat",
          "short_name":"GJ",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"India",
          "short_name":"IN",
          "types":[
            "country","political"
          ]
        }
      ],
      "formatted_address":"Ahmedabad, Gujarat 380026, India",
      "geometry":{
        "bounds":{
          "northeast":{
            "lat":23.0113677,"lng":72.6453252
          },
          "southwest":{
            "lat":22.9891871,"lng":72.60732229999999
          }
        },
        "location":{
          "lat":23.0044623,"lng":72.62575869999999
        },
        "location_type":"APPROXIMATE",
        "viewport":{
          "northeast":{
            "lat":23.0113677,"lng":72.6453252
          },
          "southwest":{
            "lat":22.9891871,"lng":72.60732229999999
          }
        }
      },
      "place_id":"ChIJ89jUeXOGXjkRICMp0qh6yZg",
      "types":[
        "postal_code"
      ]
    },
    {
      "address_components":[
        {
          "long_name":"Amraiwadi",
          "short_name":"Amraiwadi",
          "types":[
            "political","sublocality","sublocality_level_1"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "locality","political"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "administrative_area_level_2","political"
          ]
        },
        {
          "long_name":"Gujarat",
          "short_name":"GJ",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"India",
          "short_name":"IN",
          "types":[
            "country","political"
          ]
        }
      ],
      "formatted_address":"Amraiwadi, Ahmedabad, Gujarat, India",
      "geometry":{
        "bounds":{
          "northeast":{
            "lat":23.0137105,"lng":72.645556
          },
          "southwest":{
            "lat":22.989467,"lng":72.61277
          }
        },
        "location":{
          "lat":22.9996728,"lng":72.635381
        },
        "location_type":"APPROXIMATE",
        "viewport":{
          "northeast":{
            "lat":23.0137105,"lng":72.645556
          },
          "southwest":{
            "lat":22.989467,"lng":72.61277
          }
        }
      },
      "place_id":"ChIJJTsGyhKGXjkR96JPXxPnU-4",
      "types":[
        "political","sublocality","sublocality_level_1"
      ]
    },
    {
      "address_components":[
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "locality","political"
          ]
        },
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "administrative_area_level_2","political"
          ]
        },
        {
          "long_name":"Gujarat",
          "short_name":"GJ",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"India",
          "short_name":"IN",
          "types":[
            "country","political"
          ]
        }
      ],
      "formatted_address":"Ahmedabad, Gujarat, India",
      "geometry":{
        "bounds":{
          "northeast":{
            "lat":23.1378156,"lng":72.7053737
          },
          "southwest":{
            "lat":22.9028759,"lng":72.4541115
          }
        },
        "location":{
          "lat":23.022505,"lng":72.5713621
        },
        "location_type":"APPROXIMATE",
        "viewport":{
          "northeast":{
            "lat":23.1378156,"lng":72.7053737
          },
          "southwest":{
            "lat":22.9028759,"lng":72.4541115
          }
        }
      },
      "place_id":"ChIJSdRbuoqEXjkRFmVPYRHdzk8",
      "types":[
        "locality","political"
      ]
    },
    {
      "address_components":[
        {
          "long_name":"Ahmedabad",
          "short_name":"Ahmedabad",
          "types":[
            "administrative_area_level_2","political"
          ]
        },
        {
          "long_name":"Gujarat",
          "short_name":"GJ",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"India",
          "short_name":"IN",
          "types":[
            "country","political"
          ]
        }
      ],
      "formatted_address":"Ahmedabad, Gujarat, India",
      "geometry":{
        "bounds":{
          "northeast":{
            "lat":23.50846,"lng":72.84009999999999
          },
          "southwest":{
            "lat":21.9817599,"lng":71.83994
          }
        },
        "location":{
          "lat":23.022475,"lng":72.5715183
        },
        "location_type":"APPROXIMATE",
        "viewport":{
          "northeast":{
            "lat":23.50846,"lng":72.84009999999999
          },
          "southwest":{
            "lat":21.9817599,"lng":71.83994
          }
        }
      },
      "place_id":"ChIJIxcnN0CEXjkRobQIMyNYLpI",
      "types":[
        "administrative_area_level_2","political"
      ]
    },
    {
      "address_components":[
        {
          "long_name":"Gujarat",
          "short_name":"GJ",
          "types":[
            "administrative_area_level_1","political"
          ]
        },
        {
          "long_name":"India",
          "short_name":"IN",
          "types":[
            "country","political"
          ]
        }
      ],
      "formatted_address":"Gujarat, India",
      "geometry":{
        "bounds":{
          "northeast":{
            "lat":24.705709,"lng":74.4764881
          },
          "southwest":{
            "lat":20.127954,"lng":68.162834
          }
        },
        "location":{
          "lat":22.258652,"lng":71.1923805
        },
        "location_type":"APPROXIMATE",
        "viewport":{
          "northeast":{
            "lat":24.705709,"lng":74.4764881
          },
          "southwest":{
            "lat":20.127954,"lng":68.162834
          }
        }
      },
      "place_id":"ChIJlfcOXx8FWTkRLlJU7YfYG4Y",
      "types":[
        "administrative_area_level_1","political"
      ]
    },
    {
      "address_components":[
        {
          "long_name":"India",
          "short_name":"IN",
          "types":[
            "country","political"
          ]
        }
      ],
      "formatted_address":"India",
      "geometry":{
        "bounds":{
          "northeast":{
            "lat":35.513327,"lng":97.39535869999999
          },
          "southwest":{
            "lat":6.4626999,"lng":68.1097
          }
        },
        "location":{
          "lat":20.593684,"lng":78.96288
        },
        "location_type":"APPROXIMATE",
        "viewport":{
          "northeast":{
            "lat":35.513327,"lng":97.39535869999999
          },
          "southwest":{
            "lat":6.4626999,"lng":68.1097
          }
        }
      },
      "place_id":"ChIJkbeSa_BfYzARphNChaFPjNc",
      "types":[
        "country","political"
      ]
    }
  ],
  "status":"OK"
} 

因此,为了获得英文结果,您应该从位于您所在国家/地区以外的服务器发送请求,例如来自欧洲,或者尝试让 Google 相信您位于印度境外(可能使用 VPN)。

我希望这有帮助!

更新

https://maps.googleapis.com/maps/api/geocode/json?latlng=19.9276734%2C75.0116544&key=MY_API_KEY也为我提供了印地语的结果。

请注意,结果的类型是“路线”,地点 ID 是ChIJRS92AquJ2zsRGIY8TmId5OQ

如果我在地理编码器工具中打开此地点 ID,则文本也是印地语

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#place_id%3DChIJRS92AquJ2zsRGIY8TmId5OQ

如果您执行地点详细信息请求https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJRS92AquJ2zsRGIY8TmId5OQ&key=YOUR_API_KEY,您将在 Google 地图上看到此地点的直接链接

https://maps.google.com/?q=%E0%A4%B2%E0%A4%BE%E0%A4%B8%E0%A5%81%E0%A4%B0%E0%A4%97% E0%A4%BE%E0%A4%B5+%E0%A4%B0%E0%A5%8B%E0%A4%A1,+%E0%A4%B2%E0%A4%B8%E0%A5%81% E0%A4%B0,+%E0%A4%AE%E0%A4%B9%E0%A4%BE%E0%A4%B0%E0%A4%BE%E0%A4%B7%E0%A5%8D% E0%A4%9F%E0%A5%8D%E0%A4%B0+423702,+印度&ftid=0x3bdb89ab02762f45:0xe4e41d624e3c8618

谷歌地图中的文字也是印地语。

看起来带有ChIJRS92AquJ2zsRGIY8TmId5OQ表示路线的 id 的地方确实在 Google 方面存在数据问题。

我认为解决它的唯一方法是联系 Google Maps API 支持团队。希望他们能帮助解决这个数据问题。

于 2019-09-19T08:41:21.557 回答
0

您是否尝试添加区域参数:https ://maps.googleapis.com/maps/api/geocode/json?latlng=22.9997%2C72.6354&language=en®ion=EG&key=YOUR_API_KEY ?

于 2019-09-19T05:26:49.957 回答