1

ogmap完全な HTMLマップ コードへのリンク: http://code.google.com/p/earthhtml/source/browse/trunk/ogmap.html

このマップ ファイルはすべてのブラウザーから開きます(ブラウザーを 1 回最小化および最大化した後)
が、
次のように C++ コードから実行しようとすると:

void MainScreen::on_button1_clicked()
{
    map->clearCoordinates();
    map->load(QUrl("file:///home/anisha/Desktop/fwdgooglemaps/ogmaps/ogmap.html"));
}

次のエラーが表示されます。

"SyntaxError: Parse error on line:1148 Source:file:///home/anisha/Desktop/fwdgooglemaps/ogmaps/ogmap.html"

"ReferenceError: Can't find variable: GUnload on line:186 Source:file:///home/anisha/Desktop/fwdgooglemaps/ogmaps/ogmap.html" 

行番号 1148 がここに表示されます。

function preloadRasterTile (uris,tile,zoom,x,y,transparent,htmlList)
{
    var url = getTileUrl (uris,tile,zoom);
    transparent&&/MSIE 6/i.test (navigator.userAgent)?
    htmlList.push(['<div style="left:', 256*x, "px;top:", 256*y, "px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (sizingMethod = crop, src = '", url, '"', '__src__ = "'+url+'"', "></div>"].join ("")) : htmlList.push (['<img style = "position:absolute; left:',256*x," px="px">'].join(""))
}

編集:

186 行にコメントしたところ、参照エラーはなくなりましたが、構文エラーはまだ残っています。ブラウザは関係ありません。このキャッシュされたマップを qt ウィジェットにロードしています。

編集2:


コードの次の行に別のエラーが表示されます。 else if (0 < minzoom><widthinearthunits><heightinearthunits><actions.length>;i++)

機能でrepositionInlineZoomControls

javascript の index.html ファイルは次のとおりです。

Google マップ JavaScript API の例

<script type="text/javascript"> 

var map;    
var latlng            = new google.maps.LatLng (28.635308, 77.22496);

var directionsDisplay = new google.maps.DirectionsRenderer ();
var directionsService = new google.maps.DirectionsService ();

var pointsArray       = new Array();
var arrayToBeReturned = new Array();

function initialize ()
{
    var myOptions = 
    {
        zoom:4,
        center:latlng,
        mapTypeId:google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map (document.getElementById ("map"), myOptions);
    directionsDisplay.setMap (map); 
    }

    function addMarker (x, y)
{
    var initialPoint       = new google.maps.LatLng (x, y);
    var initialPointMarker = new google.maps.Marker ({
                                position:initialPoint,
                                map:map,
                                draggable:false,
                                flat:true
                                });
}

 var arrayMarkers = new Array();
var arrayIndex   = 0;

function Open(x, y)
{   var newPosition = new google.maps.LatLng (x, y);
    map.setCenter (newPosition);        

    directionsDisplay.setMap (map);


    google.maps.event.addListener (map, "click", 
                            function (event)
                            {
                                //alert("You clicked the map."+ event.latLng.toString(4));

                                arrayMarkers [arrayIndex] = event.latLng;

                                var s0  = event.latLng.lat();
                                var s1  = event.latLng.lng();
                                var s01 = new google.maps.LatLng (s0, s1);

                                var point1 = new google.maps.Marker ({
                                                                position:arrayMarkers [arrayIndex],
                                                                draggable:false,
                                                                map:map,
                                                                flat:true
                                                                }); 
                                if (arrayIndex == 1)
                                    displayRoute ();

                                arrayIndex++;
                            });

}

function displayRoute ()
 {
    var start = arrayMarkers [0];
    var end   = arrayMarkers [1];

    var request = {
                origin:start,
                destination:end,
                travelMode:google.maps.TravelMode.DRIVING
                };

    directionsService.route (request, 
                        function (result, status) 
                        {
                            if (status == google.maps.DirectionsStatus.OK)
                            {
                                directionsDisplay.setDirections (result);

                                pointsArray = result.routes[0].overview_path;

                                var i = 0;
                                var j = 0;

                                for (j = 0; j < pointsArray.length; j++)
                                {                                       
                                    arrayToBeReturned [i] = pointsArray[j].lat ();
                                    i++;
                                    arrayToBeReturned [i] = pointsArray[j].lng ();
                                    i++;

                                    var point1 = new google.maps.Marker ({
                                        position:pointsArray[j],
                                        draggable:false,
                                        map:map,
                                        flat:true
                                        });
                                }
                            }
                        });


    getCoordinates();
}

function getCoordinates ()
{       
    return arrayToBeReturned;
}

</script> 
</head>
<body onload="initialize()" topmargin="0" leftmargin="0">
<div id="map" style="width: 641px; height: 671px"></div>
<div id="directionsPanel" style="float:right;width:1000%;height 100%"></div>
</body>
</html> 
4

1 に答える 1

2

その htmlList.push 行は少なくとも少し怪しいように見えます。特に引用符の使用は私には正しくないようです。どこかでシングルクォーテーションとダブルクォーテーションが混在しているようです。たとえば、AlphaImageLoader に渡される src パラメータは、一重引用符で始まり、二重引用符で終わります。

一般に、二重引用符と単一引用符の両方を使用することは可能ですが、引用符を使用する際には一貫性を保つことをお勧めします。それは長期的には役立ちます。

おそらくもう少し冗長ですが、より読みやすい関数を使用します。引用の問題を修正しようとしました:

function preloadRasterTile (uris,tile,zoom,x,y,transparent,htmlList) 
{
    var url = getTileUrl (uris,tile,zoom);
    if (transparent && /MSIE 6/i.test(navigator.userAgent)) {
        htmlList.push([
            '<div style="left:', 256*x, 'px;',
            'top:', 256*y, 'px;',
            'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (sizingMethod = crop, src = "', url, '"', '__src__ = "'+url+'"', 
            '></div>'].join (""));
    } else {
        htmlList.push([
            '<img style = "position:absolute;',
            'left:', 256*x, 'px;">'].join(""));
    }
}
于 2012-07-09T06:55:14.593 に答える