Esa's Google Maps API experiments.
BoundsBox for v3
Geocoder returns LatLngBounds()
Bounds
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.
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.
Hint
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();
bounds.extend(point1);
bounds.extend(point2);
You cannot mess the order of the corners.
There is also a handy LatLngBounds.union() method which merges two LatLngBounds objects.