Google Earth API doesn't create place mark I want

259 views Asked by At

I'm making an ASP.net app to show some features on Google Earth. After reading "Google's Developer Guide" now i'm using this javascript code:

<script type="text/javascript" src="http://www.google.com/jsapi?hl=en&amp;key=MyAPIKey"></script>
<script type="text/javascript">
    var ge;
    google.load("earth", "1", {"other_params": "sensor=true_or_false"});

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

    function initCB(instance) {
        ge = instance;
        ge.getWindow().setVisibility(true);
    }

    function failureCB(errorCode) {
    }
    function generator() {
        // Create the placemark.
        var placemark = ge.createPlacemark('');
        placemark.setName("placemark");

        // Set the placemark's location.  
        var point = ge.createPoint('');
        point.setLatitude(12.345);
        point.setLongitude(54.321);
        placemark.setGeometry(point);

        // Add the placemark to Earth.
        ge.getFeatures().appendChild(placemark);
        alert('OK!');
    }

    google.setOnLoadCallback(init);
</script>

Then have a code like this in c# to run javascript:

b.ID = "btnSomeButton";
b.Text = "Click to generate PlaceMark!";
b.Attributes.Add("onclick", "return generator();");

My page displays the Google Earth but when I click on the button it doesn't create place mark.Where I am wrong?

1

There are 1 answers

0
Santhakumar On

I dont know what mistake in your program. It may be created successfully. I think you are searching somewhere. After placemark creation try to change your camera view. Try this code after placemark creation:

var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
lookAt.setLatitude(12.345);
lookAt.setLongitude(54.321);
lookAt.setAltitude(1000);
ge.getView().setAbstractView(lookAt);

It may work. I'm not sure.