C#谷歌地球错误

本文关键字:错误 谷歌地球 | 更新日期: 2023-09-27 17:47:48

我的一个朋友在C#用户控件中嵌入了一个谷歌地球插件。所有操作都很好,但当您关闭窗口时,我们会收到"未指定错误",并可以选择是否继续运行脚本。从我们的追踪来看,这似乎是由谷歌将其放到页面上的脚本引起的。有什么想法吗?

C#谷歌地球错误

下面是我举的一个c#/Google-Eearthneneneba API集成的例子,它涵盖了您所面临的问题(请参阅注释)http://fraserchapman.blogspot.com/2008/08/google-earth-plug-in-and-c.html

此外,这里是我的另一个项目,它使用COM Google Earth插件类型库(Plugin_ax.dll)转换为公共语言运行时程序集中的等效定义。它可能有一些用处。http://fraserchapman.blogspot.com/2008/12/google-earth-plugin-control-library.html

我们现在已经在IE和FF中尝试过了。效果很好。你知道为什么这个错误只是近距离出现的吗?我们能以某种方式禁用它吗?这是我们的代码。

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<html>
<head>
    <script src="http://www.google.com/jsapi?key=ABQIAAAAzghEPRV_D0MDzTELJ4nkXBT2AlVLQD8Rz4_aVbiXesLoyhRIMBRo399nnxv9aY-fqnkVGgTgR-pTsg">
    </script>
    <script>
        google.load("earth", "1");
        var ge = null;
        var placemark;
        function init(){
            google.earth.createInstance("map3d", initCallback, failureCallback);
        }
        function initCallback(object){
            ge = object;
            ge.getWindow().setVisibility(true);
            ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
            ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, false);
            placemark = ge.createPlacemark('');
            placemark.setName("Current Position");
            // Create style map for placemark
            var normal = ge.createIcon('');
            normal.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
            var iconNormal = ge.createStyle('');
            iconNormal.getIconStyle().setIcon(normal);
            var highlight = ge.createIcon('');
            highlight.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
            var iconHighlight = ge.createStyle('');
            iconHighlight.getIconStyle().setIcon(highlight);
            var styleMap = ge.createStyleMap('');
            styleMap.setNormalStyle(iconNormal);
            styleMap.setHighlightStyle(iconHighlight);
            placemark.setStyleSelector(styleMap);
            var options = ge.getOptions();
            options.setStatusBarVisibility(true);
            options.setScaleLegendVisibility(true);
        }
        function failureCallback(object){
            // Gracefully handle failure.
            alert("Error");
        }
        function changeViewAngle(angle){
            var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
            lookAt.setTilt(angle);
            ge.getView().setAbstractView(lookAt);
        }
        function ShowMarker(){
            ge.getFeatures().appendChild(placemark);
        }
        function MoveMarker(lon, lat){
            // Create point
            var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
            var point = ge.createPoint('');
            point.setLatitude(lat);
            point.setLongitude(lon);
            placemark.setGeometry(point);
        }
        function HideMarker(){
            ge.getFeatures().removeChild(placemark);
        }
        function SetPosition(lon, lat, heading){
            var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
            lookAt.setLatitude(lat);
            lookAt.setLongitude(lon);
            lookAt.setHeading(heading);
            ge.getView().setAbstractView(lookAt);
        }
        function SetAltitude(alt){
            var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
            lookAt.set(lookAt.getLatitude(), lookAt.getLongitude(), 0, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, lookAt.getTilt(), alt);
            ge.getView().setAbstractView(lookAt);
        }
        function ResizeMap(w, h){
            var map = document.getElementById('map3d_container');
            map.style.height = h;
            map.style.width = w;
        }
        function AddKML(kml){
            var parseKML = ge.parseKml(kml);
            ge.getFeatures().appendChild(parseKML);
            return ge.getFeatures().getLastChild().getName();
        }
        function RemoveKML(kmlName){
            if (ge.getFeatures().hasChildNodes()) {
                var nodes = ge.getFeatures().getChildNodes();
                for (var i = 0; i < nodes.getLength(); i++) {
                    var child = nodes.item(i);
                    if (child.getName() == kmlName) {
                        ge.getFeatures().removeChild(child);
                    }
                }
            }
        }
        function OptionsChanged(nav, status, scale, grid, map, terrain, road, border, building){
            var options = ge.getOptions();
            var form = document.options;
            if (nav) {
                ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
            }
            else {
                ge.getNavigationControl().setVisibility(ge.VISIBILITY_HIDE);
            }
            options.setStatusBarVisibility(status);
            options.setScaleLegendVisibility(scale);
            options.setGridVisibility(grid);
            options.setOverviewMapVisibility(map);
            ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, terrain);
            ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, road);
            ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, border);
            ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, building);
        }

    </script>
</head>
<body onload='init()'>
    <center>
        <div id='map3d_container' style='border: 1px solid silver; height: 510px; width: 767px;'>
            <DIV id=map3d style="HEIGHT: 100%">
            </DIV>
        </div>
    </center>
</body>
</html>

我运行了样本,在关闭选项卡时没有得到任何错误。

尝试这个

yourWebBrowser1.Document.Write(String.Empty);

当您关闭应用程序时。

我的问题:你能告诉我如何在C#应用程序中使用AddKML(kml)吗?根据字符串或文件路径,我两者都试过了。我正在寻找一种解析kml文件的方法。。。