Search Box:

It is used also as a result display.

No Search button!

Just type an address and click anywhere on page, or hit [Enter] key. Search is triggered by 'change' event of the text input field.

Zoom set by result

v3 geocoder result provides 'viewport' property which is used for centering and zooming the map. Examples: Europe | Finland | Helsinki | Mannerheimintie Helsinki | Mannerheimintie 6 Helsinki |

Reverse geocoding

Try rightclicking on map. The click point is sent as geocode request.

Discussion

Google Toolbar Sidewiki. Haven't one? Get it now.

Links

Blog

See the source this page or plain example with minimal html.

makeMarker()

makeMarker() with sidebar

Geocoder viewport visualized

More experiments

Rent A Coder


/**
 * geocoder
 */
var geocoder = new google.maps.Geocoder();

function geocode(opts) {
  function geocodeResult(response, status) {
    if (status == google.maps.GeocoderStatus.OK && response[0]) {
      document.getElementById("search").value = response[0].formatted_address;
      map.fitBounds(response[0].geometry.viewport);
    } else {
      alert("Sorry, " + status);
    }
  } // trim leading and trailing space with capable browsers
  if(opts.address && opts.address.trim)opts.address = opts.address.trim(); 
  if(opts.address || opts.latLng)geocoder.geocode(opts, geocodeResult); // no empty request
}

google.maps.event.addListener(map, 'rightclick', function(eve){
  geocode({latLng: eve.latLng});
});