Search code examples
htmltagskmlgoogle-earth-plugin

KML tags <Camera> and <LookAt> - doesn't work in Google Earth plugin


First, I want to thank you for the efforts in answering.

Second, I created a site that contains a plug-in of Google Earth, and I use a KML string to show two coordinates. i want to look at longitude -122.084075, latitude 37.4220033612141. when i load my website i don't see any changes.

my html code + the kml string:

<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"> </script>
<script type="text/javascript">
    var ge;
    google.load("earth", "1", {"other_params":"sensor=false"});

    function init() 
    {
        google.earth.createInstance('map3d', initCB, failureCB);    
    }

    function initCB(instance) 
    {
        ge = instance;
        ge.getWindow().setVisibility(true);
        addKmlFromString(
                            '<?xml version="1.0" encoding="UTF-8"?>' +
                            '<kml xmlns="http://earth.google.com/kml/2.0">' +
                            '<Document>' +
                            '<Placemark>' +
                            '    <name>Floating placemark</name>' +
                            '        <visibility>1</visibility>' +
                            '        <description>Floats a defined distance above the ground.</description>' +
                            '   <LookAt>' +
                            '      <longitude>-122.084075</longitude>' +
                            '      <latitude>37.4220033612141</latitude>' +
                            '      <altitude>45</altitude>' +
                            '       <heading>0</heading>' +
                            '       <tilt>90</tilt>' +
                            '       <range>100</range>' +
                            '       <altitudeMode>relativeToGround</altitudeMode>' +
                            '   </LookAt>' +
                            '   <Style>' +
                            '    <IconStyle>' +
                            '      <Icon>' +
                            '       <href>https://cdn1.iconfinder.com/data/icons/future/512/drones_watching-64.png</href> ' +
                            '      </Icon>' +
                            '     </IconStyle>' +
                            '    </Style>' +
                            '    <Point>' +
                            '     <altitudeMode>relativeToGround</altitudeMode>' +
                            '      <coordinates>-122.0822035425683,37.42228990140251,50</coordinates>' +
                            '    </Point>' +
                            '</Placemark>' +
                            '    <Placemark>' +
                            '      <name>Flight Line</name>' +
                            '      <visibility>1</visibility>' +
                            '      <description>Black line (10 pixels wide), height tracks terrain</description>' +
                            '      <styleUrl>#thickBlackLine</styleUrl>' +
                            '      <LineString>' +
                            '        <tessellate>1</tessellate>' +
                            '        <altitudeMode>relativeToGround</altitudeMode>' +
                            '       <coordinates>' +
                            '         -122.0822035425683,37.42228990140251,0' +
                            '         -122,37.8,0' +
                            '       </coordinates>' +
                            '     </LineString>' +
                            '   </Placemark>' +
                            '<Placemark><name>From</name><Point><coordinates>-122.0822035425683,37.42228990140251,0</coordinates></Point></Placemark>' +
                            '<Placemark><name>To</name><Point><coordinates>-122,37.8,0</coordinates></Point></Placemark>' +
                            '</Document>' +
                            '</kml>'
                          );
    }

    function addKmlFromString(kmlString)
        {
            var kmlObject = ge.parseKml(kmlString);

            ge.getFeatures().appendChild(kmlObject);
        }

        function failureCB(errorCode) 
        {

        }



        google.setOnLoadCallback(init);
</script>

</head>
<body>
<div id="map3d" style="height: 300px; width: 400px;"></div>
</body>
</html>

please guide me. what am i doing wrong? Thanks a lot!


Solution

  • I found the answer right here: https://developers.google.com/earth/documentation/camera_control#flytospeed

    Zooming the camera

    Zooming in and out is controlled by the range attribute for a LookAt, and the altitude attribute for a Camera.

    Note that changing the altitude attribute of a LookAt changes the altitude of the point being viewed. Because the viewer range is relative to this point, the viewer's altitude is also changed.

    LookAt:

    // Get the current view.
    var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
    
    // Zoom out to twice the current range.
    lookAt.setRange(lookAt.getRange() * 2.0);
    
    // Update the view in Google Earth.
    ge.getView().setAbstractView(lookAt);