Google maps api 3 来自互联网的谷歌地图HTML示例赢得';我不能在我的计算机上打开,但我可以在Internet URL上打开
我正在尝试从我的计算机打开html文件。我可以在internet上打开它,但如果我查看页面源代码并将其保存为HTML文件,则我无法打开,或者我可以打开,但不会显示标记。 使用的XML是本地的,所以我也下载了它,并把它和html文件放在同一个文件夹中。如何解决这个问题?因为我想更改此文件以满足我的需要 谢谢 我的HTML(没有必要的东西,比如css,adds…)现在看起来像这样:Google maps api 3 来自互联网的谷歌地图HTML示例赢得';我不能在我的计算机上打开,但我可以在Internet URL上打开,google-maps-api-3,Google Maps Api 3,我正在尝试从我的计算机打开html文件。我可以在internet上打开它,但如果我查看页面源代码并将其保存为HTML文件,则我无法打开,或者我可以打开,但不会显示标记。 使用的XML是本地的,所以我也下载了它,并把它和html文件放在同一个文件夹中。如何解决这个问题?因为我想更改此文件以满足我的需要 谢谢 我的HTML(没有必要的东西,比如css,adds…)现在看起来像这样: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
//<![CDATA[
// this variable will collect the html which will eventually be placed in the side_bar
// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
// global "map" variable
var map = null;
// A function to create the marker and set up the event window function
function createMarker(latlng, name, html) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
zIndex: Math.round(latlng.lat()*-100000)<<5
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
});
// save the info we need to use later for the side_bar
gmarkers.push(marker);
}
// This function picks up the click and opens the corresponding info window
function myclick(i) {
google.maps.event.trigger(gmarkers[i], "click");
}
function initialize() {
// create the map
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(43.907787,-79.359741),
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
// Read the data from example.xml
downloadUrl("example.xml", function(doc) {
var xmlDoc = xmlParse(doc);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new google.maps.LatLng(lat,lng);
var html = markers[i].getAttribute("html");
var label = markers[i].getAttribute("label");
// create the marker
var marker = createMarker(point,label,html);
}
// put the assembled side_bar_html contents into the side_bar div
//document.getElementById("side_bar").innerHTML = side_bar_html;
});
}
var infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});
//]]>
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<!-- you can use tables or divs for the overall layout -->
<table border="1">
<tr>
<td>
<div id="map_canvas" style="width: 1050px; height: 1050px"></div>
</td>
</tr>
</table>
<noscript><p><b>JavaScript must be enabled in order for you to use Google Maps.</b>
However, it seems JavaScript is either disabled or not supported by your browser.
To view Google Maps, enable JavaScript by changing your browser options, and then
try again.</p>
</noscript>
//--></script>
</body>
</html>
//
必须启用JavaScript才能使用Google地图。
但是,您的浏览器似乎禁用或不支持JavaScript。
要查看Google地图,请通过更改浏览器选项启用JavaScript,然后
再试一次
//-->
您不能这样做。HTML将呈现,但由于本地计算机上不存在所有资源(css、js、图像等),因此会出现大量错误。您需要使用Maps API来构建自己的解决方案。嗨,乔,谢谢您的回答。我删除了html中所有不必要的东西。我的地图已打开,但没有标记。你知道我还需要删除什么才能让这一切顺利吗?因为我之前下载的一些示例是从我的计算机上下载的,在您试图在本地复制的页面的源代码中,请尝试查找可以复制到本地目录的外部js和css资源。然后,在HTML中连接它们的引用。这会让你更接近,乔,你解决了。我只需要一个js文件,然后它就工作了。若你们知道可能的解决办法,对此我将非常感激。如果没有,无论如何谢谢你!溴