v2.82: Set Country/Viewport Restrictions in your GClientGeocoder for More Tailored Results

Monday, June 18, 2007 at 6:46:00 PM

In the latest v2.82 release of the API, we've added 2 additional functions to the GClientGeocoder: setViewport, and setBaseCountryCode. These two functions will help you instruct the geocoder to prefer results within a certain area or country (but not to restrict the results).

In the example below, you can test out the influence of setBaseCountryCode. Enter a country code in the first box and the address in the second, and then change the country code and see if the result changes. The 2-character country code must be ISO-compliant and correspond to a Google Maps domain (e.g. "US" for google.maps.com, "AU" for google.maps.com.au). Hint: Try out "Syracuse" for "IT" vs. "US" or "Toledo" for "ES" vs. "US".

In this next example, you can test out the influence of setViewport, which is typically more powerful than setBaseCountryCode. Here, I've modified the just-released DragZoomControl to let you continually drag rectangles on the map. After you've finished drawing a rectangle, it will pass the GLatLngBounds of that rectangle to GClientGeocoder.setViewport, and then fire off a request to geocode the address in the text box. Try dragging rectangles of various sizes for the same address to understand the full effect of setViewport.

Note: Remember that you'll need to specify v=2.x in your script tag to use the new functions for the next few weeks, since they're new features. More information on API script versioning is here.

API v2 Latest (v=2.x): 2.82
API v2 Default (v=2): 2.81