The Google Geocode area only works in certain cases.

I think this is a mistake, and I'm going to figure out where to send it to Google, but I thought that I would ask here first if I just did something wrong or misinterpreted it. I can't get Google geocoder to use region offset sequentially. For example, the following works:

  • https://maps.googleapis.com/maps/api/geocode/json?address=boston returns Boston, Massachusetts
  • https://maps.googleapis.com/maps/api/geocode/json?address=boston®ion=uk returns Boston, Lincolnshire in England

However, the following does not work

  • https://maps.googleapis.com/maps/api/geocode/json?address=manchester returns Manchester, UK
  • https://maps.googleapis.com/maps/api/geocode/json?address=manchester®ion=us still returns Manchester, UK

Both Boston, Lincolnshire and Manchester, CT, do not appear in the results for queries without registers, so I believe that they should work the same. However, it is important to note that it may depend on entries in the manual region. The following does not work properly, and both return to Boston, Massachusetts:

  • https://maps.googleapis.com/maps/api/geocode/json?address=boston®ion=ca should be Boston, Ontario
  • https://maps.googleapis.com/maps/api/geocode/json?address=boston®ion=us-ky must be Boston, KY

EDIT: JS API

The accepted answer from @ dr-molle is correct. However, you are using the Google JS API, you cannot specify components . However, you can specify a bounding area in bounds . To find your borders, you need LatLng objects for NE and SW points of a rectangle. For CT, I did the following:

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

EDIT 2: componentRestrictions

The JavaScript API accepts a componentRestrictions object. You will see that the documents do not display componentRestrictions in the object literal, but it describes it below (where it does not mention that it is an object). The code in the first rule above can be simplified to:

 geocoder = new google.maps.Geocoder(); geocoder.geocode({ address: 'manchester', componentRestrictions: { administrativeArea: 'CT' } }, someCallbackFunction); 
+1
source share
1 answer

From the documentation:

Note that bias only prefers results for a specific domain; if more relevant results exist outside this domain, they may be included.

To limit the results to a specific country, use Component Filtering

eg. https://maps.googleapis.com/maps/api/geocode/json?address=manchester&components=country:US

+4
source

Source: https://habr.com/ru/post/947909/


All Articles