looking at multiple placemarks

104 views
Skip to first unread message

NikVdW

unread,
Oct 12, 2009, 3:19:19 PM10/12/09
to KML Developer Support - Google Earth Plug-in
Dear group,

I'm trying to replicate the behavior of looking at a bounding box in
Google Maps. I have multiple (moving) placemarks I want to be looking
at, at the same time.

I can look at every single one just fine, but with KmlLookAt and
KmlCamera objects.
I have tried working with the Maps API LatLngBounds class, where I can
use getCenter to get a focal point, but I haven't found a way to
determine zoomlevel to get them both into the picture.

Any suggestions are greatly appreciated!
kind regards,
Nik.

StarTraX

unread,
Oct 13, 2009, 1:59:31 AM10/13/09
to KML Developer Support - Google Earth Plug-in
I think you're just going to have to "do the math". You have the
centre, now you need the distance to the outermost point (use
haversine formula (google it)) and, using that as a base calculate the
height of the triangle required to give an apex angle of 25 degrees
(the GE view is around 50 degrees).
Then the height is the range of the LookAt.

NikVdW

unread,
Oct 13, 2009, 6:57:06 AM10/13/09
to KML Developer Support - Google Earth Plug-in
Thanks for the suggestion!

I just managed to come up with another, very easy, solution. I had not
looked into the GeoJS and GEarthExtensions, and they allow me to
define a bounds and set a view to it!

thanks again though,
Nik.

sfletche

unread,
Dec 10, 2009, 5:54:03 PM12/10/09
to KML Developer Support - Google Earth Plug-in
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

sfletche

unread,
Dec 10, 2009, 5:54:25 PM12/10/09
to KML Developer Support - Google Earth Plug-in
Reply all
Reply to author
Forward
0 new messages