Google Geocoding API为我的服务器和Web浏览器提供了不同的结果 [英] Google Geocoding API giving different results to my server and my web browser

查看:76
本文介绍了Google Geocoding API为我的服务器和Web浏览器提供了不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Geocoding API来获取网站上不同位置搜索的经/纬度坐标.问题是,对于伦敦地区(可能不仅仅限于伦敦,这是我们大多数用户所在的地区),例如滑铁卢",地理编码api返回的结果与我直接将url直接放入服务器时的结果不同我的浏览器.这是为滑铁卢生成的网址:

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:

如果我将其粘贴到浏览器中,则会得到正确的滑铁卢区域(滑铁卢,兰贝斯伦敦自治市镇,英国伦敦SE1").但是,当我的服务器从该URL检索结果时,它将获得地址"2C Waterloo Rd,伦敦,大伦敦NW2 7UA,英国",该地址距离Waterloo数英里. (它也只返回一个结果.)

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.)

我的服务器位于英国,在IP上执行GeoIP确认了这一点. Google为什么会向我的服务器返回不同的结果?

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?

(顺便说一句,我的服务器正在使用PHP5 simplexml_load_file()来检索结果)

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

**我不明白为什么这个问题被标记为另一个问题的重复.这是一个假定的重复问题,丝毫没有回答我的问题,我的问题与企业(仅邮政地区)无关,也无法解释为什么我的服务器与PC区别对待.

** 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.

推荐答案

您遇到的是区域偏向": https://developers.google.com/maps/documentation/geocoding/#RegionCodes

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

传递region=uk GET参数,结果在任何地方都应该相同(即为英国量身定制).

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

这篇关于Google Geocoding API为我的服务器和Web浏览器提供了不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆