开发者

GMaps api Geocode strange behavior

开发者 https://www.devze.com 2023-03-06 23:45 出处:网络
I\'m using gmaps apiv3 webservice to geocode with latlng couple. It\'s pretty simple but I have a strange behavior for some data.

I'm using gmaps apiv3 webservice to geocode with latlng couple. It's pretty simple but I have a strange behavior for some data.

Eq:

http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&region=fr&latlng=46.16141,-1.149797

Next I open url with a navigator (firefox / chrome) and at line formatted_address the value is :

<formatted_address>57-79 Rue des Merciers, 17000 La Rochelle, France</formatted_address>

But when I get xml file through PHP

$xml = simplexml_load_file($url);
var_dump($xml)

result :

public 'forma开发者_开发问答tted_address' => string '57-79 Rue des Merciers, 17000 Rochelle, France' (length=46)

the word 'La' before 'Rochelle' just disapear ... That my problem. And it's not a unique case (I can post more example).

I try also try with file_get_contents, curl, wget ... Same result


This is because the formatted street address is locale-aware and reacts to your browser's accept-language header, which probably is fr-FR.

If you would encode a position in London, you would get Londres in a french-language browser, London in an english one, Lontoo in a finnish one etc.

Use the language parameter to force the language.

http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&
region=fr&latlng=46.16141,-1.149797&language=fr
0

精彩评论

暂无评论...
验证码 换一张
取 消