Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Earth Determining zoom level from bounding box

I got a Windows Forms app making use of Google Earth where users can draw a polygon on the map which is used as a geofence.

What I'd like to do is to be able to zoom to the polygon so that it fits nicely on screen with a click of a button. A sort of zoom to fit function.

Finding the centre of the polygon and setting the Google Earth camera to that lat/long is easy.

What I need is an algorithm that takes a bounding box of lats \ longs, screen height \ width and then determines the altitude to set the camera.

Does anyone have this algorithm or know where one can be found?

Thanks!!

like image 532
Dominic Avatar asked Jul 14 '10 15:07

Dominic


People also ask

How do I check the zoom level on Google Maps?

You can change the zoom level of the map using simple steps. Step 1 Go to Add or Edit Map page . Step 2 Select 'Default zoom level' in the 'Map Information section'. Step 3 click save map and see the changes.

Which method is used to get the current zoom level of the map?

Maps API getZoom() Method The getZoom() method returns the current zoom level of the map.


1 Answers

To "zoom to the polygon" or any other KmlObject it is probably easiest to use the earth-api-utility-library.

See the methods createBoundsView, setToBoundsView and especially flyToObject

For example, where ge is the GEPlugin object and polygon is a KmlPolygon.

var gex = new GEarthExtensions(ge);
gex.util.flyToObject(polygon, { boundsFallback: true, aspectRatio: 1 } );
like image 86
Fraser Avatar answered Sep 17 '22 19:09

Fraser