我认为这是一个错误,我会找出将它提交给谷歌的地方,但我想我会先问这里以防万一我做错了什么或者误解某些东西。我无法让Google的地理编码器始终如一地使用地区偏见。例如,下面做工作:谷歌地理编码区域只适用于某些情况
https://maps.googleapis.com/maps/api/geocode/json?address=boston
返回波士顿,MAhttps://maps.googleapis.com/maps/api/geocode/json?address=boston®ion=uk
返回波士顿,林肯郡英国
但是以下不起作用
https://maps.googleapis.com/maps/api/geocode/json?address=manchester
返回曼彻斯特,英国https://maps.googleapis.com/maps/api/geocode/json?address=manchester®ion=us
still re转身英国的曼彻斯特
波士顿,林肯郡和曼彻斯特,CT都没有出现在无区域要求的结果中,所以我相信他们应该工作一样。但是,需要注意的是,它可能依赖于手动区域条目。预期后续不工作,都返回波士顿,MA:
https://maps.googleapis.com/maps/api/geocode/json?address=boston®ion=ca
应该是波士顿,安大略https://maps.googleapis.com/maps/api/geocode/json?address=boston®ion=us-ky
应该是波士顿,KY
编辑:JS API
的@ dr-molle接受的答案是正确的。但是,您正在使用Google的JS API,因此无法指定components
。不过,您可以在bounds
中指定边界区域。要找到您的边界,您需要一个矩形框的NE和SW点的对象。对于CT我做了以下内容:
CT_NE_POINT = new google.maps.LatLng(42.05, -71.783333);
CT_SW_POINT = new google.maps.LatLng(40.966667, -73.733333);
CT_BOUNDS = new google.maps.LatLngBounds(CT_SW_POINT, CT_NE_POINT);
...
geocoder = new google.maps.Geocoder();
geocoder.geocode({address: 'manchester', bounds: CT_BOUNDS}, someCallbackFunction);
编辑2:componentRestrictions
中的JavaScript API不接受componentRestrictions
对象。您会看到the docs在对象字面值中未显示componentRestrictions
,但它在下面描述了它(它没有提及它是对象)。在上面的第一个编辑的代码可以被简化为:
geocoder = new google.maps.Geocoder();
geocoder.geocode({
address: 'manchester',
componentRestrictions: { administrativeArea: 'CT' }
}, someCallbackFunction);
这里报告为bug https://code.google.com/p/gmaps-api-issues/issues/detail?id=7419由我于12/3/14 – Aaron 2014-12-03 16:55:01