Google Geocoding API giving different results to my server and my web browser [duplicate]

人走茶凉 提交于 2019-12-01 05:01:26

问题


I'm using the Google Geocoding API to get the lat/lng co-ordinates for different location searches on my site. The problem is that for areas of London (it might not be restricted to just London that's just where most of our user base is) such as "Waterloo" the geocoding api is returning different results to my server from when i put the url directly in my browser. This is the url that is generated for waterloo:

http://maps.googleapis.com/maps/api/geocode/xml?address=waterloo,%20london,%20england&bounds=48.8,-11.2|60.9,1.9&sensor=false&region=uk

If i paste this into my browser I get the correct area of Waterloo ("Waterloo, London Borough of Lambeth, London SE1, UK"). However, when my server retrieves the results from this url it gets the address "2C Waterloo Rd, London, Greater London NW2 7UA, UK" which is miles away from Waterloo. (It is only returning a single result too.)

My server is based in the UK and doing an GeoIP on the IP confirms this. Why would Google return different results to my server?

(BTW my server is using PHP5 simplexml_load_file() to retrieve the results)

** I don't understand why this question has been marked as a duplicate of another. The question this is a supposed duplicate of does not answer my question in the slightest, my question has nothing to do with businesses (only postal regions) and does not explain why my server is being treated differently to my PC.


回答1:


You're experiencing something called Region Biasing: https://developers.google.com/maps/documentation/geocoding/#RegionCodes

Pass a region=uk GET parameter and your results should be the same (i.e. tailored to the UK) everywhere.



来源:https://stackoverflow.com/questions/10302302/google-geocoding-api-giving-different-results-to-my-server-and-my-web-browser

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