Search code examples
google-maps-api-3google-geocoder

Restricting geocoding to a country


I have seen that it is possible with the "static" to limit the scope of the search to a certain area (with components restrictions), I have also seen that in release 3.exp (will be 3.14) of the JavaScript API, a new class google.maps.GeocoderComponentRestrictions has appeared. I have not seen anywhere how this class is supposed to be used though. Does anyone have more information about this?


Solution

  • It looks like this was answered over at Google Maps Geocoding API, feature from the API missing in their JS api (?), with formatting like:

    geocoder.geocode( 
          { 'address': address, 'componentRestrictions':{'country':'GB'}}, 
    function(results, status){
    ...   
    });
    

    The GeocoderComponentRestrictions parameters get passed with the componentRestrictions key.