指向完整html ogmap
地图代码的链接:http://code.google.com/p/earthhtml/source/browse/trunk/ogmap.html
此地图文件将从所有浏览器打开(在最小化和最大化浏览器之后),
但
当它尝试从我的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 Maps 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>
答案 0 :(得分: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(""));
}
}