Not able to get formated_address 'only in English' getting some part of result in regional language

纵饮孤独 提交于 2021-02-10 23:28:30

问题


I'm getting some part of google map result in regional language need complete result in ENGLISH

I have tried hitting map's API with changing the language to 'en' and region to 'IN'

$geocode=file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?latlng=12.9415554,77.5595728&sensor=false&key=MYAPIGOOGLEKRY&language=en&region=IN);
        $geocode_arr=json_decode($geocode,true);
        if(array_key_exists("0",$geocode_arr['results'])){
        $arr_exp=explode(",",$geocode_arr['results'][0]['formatted_address']);
        $arr_exp=array_slice($arr_exp, -4, 3, true);
        $address_str=implode(",",$arr_exp);
        print_r($address_str); exit;
        }

Getting result :

ಬನಶಂಕರಿ, Bengaluru, Karnataka 560050 
('ಬನಶಂಕರಿ' regional language)

Expected Result :

XYZ, Bengaluru, Karnataka 560050

回答1:


This is intended behavior from the Maps APIs. At this time it's not possible to return formatted_address in English only. Refer to Google's post on Localization of Street Addresses in the Google Maps APIs.

Street-level addresses returned by the Google Maps Geocoding API now favor the local language, while keeping the address understandable as much as possible for both a user who only reads the requested language as well as locals.

If the local language and user language both use the same alphabet, the Geocoding API will now return the local names for the streets and localities. For example, searching for an address in Brazil with user language set to English now returns “Avenida Paulista” rather than “Paulista Avenue”.

So this example request:

https://maps.googleapis.com/maps/api/geocode/json?address=Avenida+Paulista,+Bela+Vista&key=KEY

returns this:

formatted_address: "Av. Paulista - Bela Vista, São Paulo - SP, Brazil"

The Geocoding documentation also mentions this:

The geocoder does its best to provide a street address that is readable for both the user and locals. To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user if necessary, observing the preferred language. All other addresses are returned in the preferred language. Address components are all returned in the same language, which is chosen from the first component.

Hope this answers your question.



来源:https://stackoverflow.com/questions/57652053/not-able-to-get-formated-address-only-in-english-getting-some-part-of-result-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!