谷歌地球API不会创建我想要的地标

Google Earth API doesn't create place mark I want

本文关键字:我想要 创建 API 谷歌地球      更新时间:2023-09-26

我正在制作一个 ASP.net 应用程序来显示Google地球上的一些功能。在阅读了"Google的开发人员指南"之后,我现在正在使用以下JavaScript代码:

<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>

然后在 c# 中有一个这样的代码来运行 javascript:

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

我的页面显示谷歌地球,但当我点击按钮时,它不会创建地标。我错在哪里?

我不知道

你的程序有什么错误。它可能已成功创建。我想你正在某个地方搜索。创建地标后,尝试更改相机视图。创建地标后尝试以下代码:

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);

它可能会起作用。我不确定。