我确信这是一个非常基本的东西,但我已经看了一个小时,我看不到它。我很欣赏一双新鲜的眼睛。这是一个非常基本的Google Maps API v3项目,几乎从菜谱中逐字复制,将数据从MySQL数据库加载到XML文件中,然后将数据从XML文件加载到地图中。
以下是XML文件中的3个示例标记:
<markers>
<marker name="Total Beverage" type="2" address="9359 Sheridan Blvd Wesminster, CO 80031" lat="-105.053293" lon="39.8658159"/>
<marker name="Union Jack Liquor" type="2" address="1160 S Boulder Road Louisville, CO 80027" lat="-105.1301647" lon="39.9868051"/>
<marker name="Argonaut Wine and Liquor" type="2" address="760 E Colfax Denver, CO 80203" lat="-104.9785574" lon="39.7398985"/>
</markers>
这是生成地图的代码。
<!DOCTYPE html >
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Big Choice Sample Map</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map { height: 100% }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var customIcons = {
0: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_yellow.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
1: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
2: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
function load() {
var latlng = new google.maps.LatLng(39.909939, -105.078369);
var options = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), options);
var infoWindow = new google.maps.InfoWindow;
downloadUrl("phpsql_genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var type = parseInt(markers[i].getAttribute("type"));
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lon")));
var html = "<b>" + name + "</b>";
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
title: name,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
</script>
</head>
<body style="margin:0px; padding:0px;" onload="load()">
<div id="map" style="width:100%; height:100%"></div>
</body>
</html>
地图位于正确的位置,并缩放到正确的水平,但标记不会显示。谢谢你的任何指示。
答案 0 :(得分:4)
xml中有纬度和经度:
lat="-105.053293" lon="39.8658159"
您的地图位于以下位置:
var latlng = new google.maps.LatLng(39.909939, -105.078369);