这是我的字符串,我正在传递给地理编码器服务 .
http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Lindon®ion=GB&componentRestrictions=locality
其中region = GB是英国的国家代码,而不是伦敦我在Lindon . Componentrestrictions = locality应该仅适用于城市!
但是我的结果又回到了美国的一些地方!
这不是你如何使用谷歌地理编码器的组件限制?
如果传递'Lindon',我不希望看到任何结果,特别是对于美国 .
2 回答
为地址参数添加“,GB” .
http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Lindon,UK®ion=GB&componentRestrictions=locality&language=en
region参数只是"biasing",不受区域限制 . https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRegionCodes
根据我的经验,添加国家代码,邮政编码,适用于所有大多数情况 .
没有参数
componentRestrictions
(此参数属于Javascript-API),Webservice的参数名为components
组件必须具有名称(例如
locality
) and 一个值 . 在您的情况下,当您想要搜索名为 Lindon 的城市时,它应该是locality:Lindon
region
-parameter不限制结果,它只会偏好给定区域的结果 . 如果要将结果限制为GB,请使用组件country:gb
.城市的样本请求 Washington (因为似乎没有城市Lindon in the UK)
http://maps.googleapis.com/maps/api/geocode/xml?components=locality:Washington|country:gb