Geocoder returns LatLngBounds()

V3 geocoder returns bounds of the search result as a handy LatLngBounds object (blue). Targets without bounds, like street numbers, return a 'viewport' property as LatLngBounds (red). BoundsBox extension is used for visualizing the results. The info window points to the actual location returned.

A few examples: MA | Maine | Main st | 1 Main st | USA | Europe


At time of writing (July 2009) API v3 does not support polylines. BoundsBox is an extension for drawing rectangles on v3 map by coordinates. The generated rectangle is a <DIV> element that is overlayed on map. BoundsBox is a subclass of OverlayView. Get the code Usage:
new BoundsBox(Map, LatLngBounds, {opt_options});

BoundsBox optional options object

Property Type Description
html string Html contents of the div.
className string CSS class of the div. Default: "bounds-box"
fit boolean If true, map viewport will be fitted to bounds of the box.

BoundsBox methods

Method Return Value Description
remove() - Removes the div from DOM.
getPosition() LatLng Returns center LatLng of the box. Makes it possible to use BoundsBox as an InfoWindow anchor.
setContent(string) - Sets innerHTML of the div.
getContent() string Returns innerHTML of the div.
setClassName(string) - Sets CSS class of the div.
getClassName() string Returns CSS class of the div.
getDiv() html object Returns reference to the div.
getSize() Size Returns dimensions of the div as a Size object.

BoundsBox events

Event Parameters Description
click Mouse event Fired when user clicks on the div. On overlapping divs, the topmost takes the click.
Other DOM event listeners can easily be attached to the div by getDiv() method.


The constructor of LatLngBounds() takes two LatLng() objects as parameters.
var bounds =
google.maps.LatLngBounds(point1, point2);

The order of those is essential. Give them in wrong order and getCenter() leads you (your visitors) on the opposite side of the Earth. A perfect opportunity to make errors that cause weird behavior. Instead I suggest doing it:
var bounds = google.maps.LatLngBounds();
You cannot mess the order of the corners.

There is also a handy LatLngBounds.union() method which merges two LatLngBounds objects.

Reverse geocoding

Try rightclicking on map and click [Search].

New versions

BounsdBox is under continuous development.


More experiments

Overlaying images (v1.0)

Overlays with km size (v1.1)