我正在使用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=en
或Accept-Language=en-US
但不起作用。 - 尝试使用
language=en
和hl=en
但不起作用。
我相信这可能是一种预期的行为。Google 在地理编码 API 响应中偏爱本地语言,以防地址本地语言与用户语言具有相同的字母表。
以下博客文章中介绍了此行为
https://mapsplatform.googleblog.com/2014/11/localization-of-street-addresses-in.html
如果本地语言和用户语言都使用相同的字母,则地理编码 API 现在将返回街道和地点的本地名称。例如,在巴西搜索用户语言设置为英语的地址现在返回"保利斯塔大道"而不是"保利斯塔大道"。
如果本地语言和用户语言使用不同的字母,则地理编码 API 将返回本地名称(音译为拉丁字母(。在某些情况下,可能会返回英文翻译,例如,如果没有可用的音译。For example, searching for El Tahrir Square with user language set to Japanese now returns "El-Tahrir Square, Ismailia, Qasr an Nile, Cairo Governorate, エジプト" rather than "エジプト カイロ県 Qasr an Nile, タハリール広場" (the old result) or "ميدان التحرير، قصر النيل، محافظة القاهرة، مصر" (the local name).
也许谷歌检测到您的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,+India&ftid=0x3bdb89ab02762f45:0xe4e41d624e3c8618
谷歌地图中的文字也是印地语。
看起来带有 idChIJRS92AquJ2zsRGIY8TmId5OQ
表示路线的地方确实在 Google 方面存在数据问题。
我认为解决这个问题的唯一方法是联系谷歌地图API支持团队。希望他们可以帮助解决此数据问题。
您是否尝试添加区域参数:https://maps.googleapis.com/maps/api/geocode/json?latlng=22.9997%2C72.6354&language=en®ion=EG&key=YOUR_API_KEY?