google map app javascript xml簡単な地図を生成します.

4164 ワード

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=http://www.w3.org/1999/xhtml xmlns:v="urn:schemas-microsoft-com:vml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
		<title></title>
			<script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript" charset="UTF-8"></script>
			<script src=http://maps.google.com/maps?file=api&v=2 type="text/javascript"></script>
			<script type="text/javascript">
				/* aa.xml
				<?xml version="1.0" encoding="utf-8"?>
				<markers>    
				   <marker lat="29.94176113301537" lng="112.6857368551186" add="  2"/> 
				   <marker lat="28.94176113301537" lng="112.6857368551186" add="  3"/> 
				   <marker lat="28.94176113301537" lng="111.6857368551186" add="  4"/>
				   <marker lat="30.94176113301537" lng="112.6857368551186" add="  5"/>
				</markers>
				*/
				
				//        
				function init() {
					function createMarker(point,addStr,sthStr){
						var infoTabs = [  new GInfoWindowTab("  ", addStr),  new GInfoWindowTab("  ", sthStr)];
						var marker = new GMarker(point);
						GEvent.addListener(marker, "click", function() {  
							marker.openInfoWindowTabsHtml(infoTabs);
						});
						return marker;
					}
					var map = new GMap(document.getElementById("map"));   
					map.addControl(new GSmallMapControl());  
					map.setCenter(new GLatLng(36.94,106.08),4);
					GDownloadUrl("aa.xml", function(data, responseCode) {   
						var xml = GXml.parse(data);   
						var markers = xml.documentElement.getElementsByTagName("marker");   
						for (var i = 0; i < markers.length; i++) { //alert(markers[i].getAttribute("add"));
							var addStr = markers[i].getAttribute("add");
							var sthStr = markers[i].getAttribute("add");
							var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),	parseFloat(markers[i].getAttribute("lng")));   
							//var markerPoint = new GMarker(point);
							map.addOverlay(createMarker(point, addStr,sthStr));
						}   
					});
				}
				//     
				/*function init() {
					function createMarker(point,addStr){
						var marker = new GMarker(point);
						GEvent.addListener(marker, "click", function() {  
							marker.openInfoWindowHtml(addStr);
						});
						return marker;
					}
					var map = new GMap(document.getElementById("map"));   
					map.addControl(new GSmallMapControl());  
					map.setCenter(new GLatLng(36.94,106.08),4);
					GDownloadUrl("aa.xml", function(data, responseCode) {   
						var xml = GXml.parse(data);   
						var markers = xml.documentElement.getElementsByTagName("marker");   
						for (var i = 0; i < markers.length; i++) { //alert(markers[i].getAttribute("add"));
							var addStr = markers[i].getAttribute("add");
							var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),	parseFloat(markers[i].getAttribute("lng")));   
							//var markerPoint = new GMarker(point);
							map.addOverlay(createMarker(point, addStr));
						}   
					});
				}*/
				
			</script>
	</head>
	<body onload="init()">
		<div id="map" style="width: 840px; height: 480px; float:left; border: 1px solid black;"></div>
		</div>
	</body>
</html>