I came upon this post earlier today and was disheartened to see only
the faint glow of a solution offered by Nik (although I'm much obliged
to Nik for providing that direction, as it provided all the clues
necessary for me to solve my own problem), so after I put together
something pretty similar I thought I'd post it here to provide a
little more direction to others facing such problems...
Basically, I was using Geocoder.geocode() to send the Earth viewer to
a location entered by the user. I wanted the zoom level / bounding
box to be appropriate to the location requested (e.g. larger view area
for cities, smaller view area for street addresses).
Geocoder.geocode() requires a callback function to which it passes a
results value. This results value provides a viewport (a LatLngBounds
object) which is basically the recommended bounding box for viewing
the geocoded location:
var viewport = results[0].geometry.viewport;
from here I created a couple geo.Point objects from the southwest and
northeast corners of viewport:
var sw = new geo.Point(viewport.getSouthWest());
var ne = new geo.Point(viewport.getNorthEast());
with these geo.Point objects I created a geo.Bounds object:
var bounds = new geo.Bounds(sw, ne);
which can then be used to generate a KmlAbstractView:
var bounding_view = gex.view.createBoundsView(bounds, {aspectRatio:
1.0});
which is what I really wanted all along, so that I could set the
abstract view of my Google Earth viewer:
ge.getView().setAbstractView(bounding_view);
and voila, the viewer flies to the geocoded location at an
appropriately zoomed level.
And just for good measure, I added a point placemark with the location
name:
var point = results[0].geometry.location;
gex.dom.addPointPlacemark([point.lat(), point.lng()], {name:
location});
I hope this is useful for anyone else trying to assign an appropriate
bounding box with the Google Earth viewer for a given geocoded
location.
-Scott