박정인

result

Showing 1 changed file with 104 additions and 0 deletions
1 +<!DOCTYPE html >
2 + <head>
3 + <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
4 + <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
5 + <title>Using MySQL and PHP with Google Maps</title>
6 + <style>
7 + /* Always set the map height explicitly to define the size of the div
8 + * element that contains the map. */
9 + #map {
10 + height: 100%;
11 + }
12 + /* Optional: Makes the sample page fill the window. */
13 + html, body {
14 + height: 100%;
15 + margin: 0;
16 + padding: 0;
17 + }
18 + </style>
19 + </head>
20 +
21 + <body>
22 + <div id="map"></div>
23 +
24 + <script>
25 + var customLabel = {
26 + Seochogu: {
27 + label: 'R'
28 + },
29 + Seongdonggu: {
30 + label: 'B'
31 + }
32 + Gwanakgu: {
33 + label: 'G'
34 + }
35 + Gangnamgu: {
36 + label: 'G'
37 + }
38 + };
39 +
40 + function initMap() {
41 + var map = new google.maps.Map(document.getElementById('map'), {
42 + center: new google.maps.LatLng(37.551920, 127.994615),
43 + zoom: 12
44 + });
45 + var infoWindow = new google.maps.InfoWindow;
46 +
47 + // Change this depending on the name of your PHP or XML file
48 + downloadUrl('http://127.0.0.1/test.xml', function(data) {
49 + var xml = data.responseXML;
50 + var markers = xml.documentElement.getElementsByTagName('marker');
51 + Array.prototype.forEach.call(markers, function(markerElem) {
52 + var name = markerElem.getAttribute('name');
53 + var address = markerElem.getAttribute('address');
54 + var type = markerElem.getAttribute('type');
55 + var point = new google.maps.LatLng(
56 + parseFloat(markerElem.getAttribute('lat')),
57 + parseFloat(markerElem.getAttribute('lng')));
58 +
59 + var infowincontent = document.createElement('div');
60 + var strong = document.createElement('strong');
61 + strong.textContent = name
62 + infowincontent.appendChild(strong);
63 + infowincontent.appendChild(document.createElement('br'));
64 +
65 + var text = document.createElement('text');
66 + text.textContent = address
67 + infowincontent.appendChild(text);
68 + var icon = customLabel[type] || {};
69 + var marker = new google.maps.Marker({
70 + map: map,
71 + position: point,
72 + label: icon.label
73 + });
74 + marker.addListener('click', function() {
75 + infoWindow.setContent(infowincontent);
76 + infoWindow.open(map, marker);
77 + });
78 + });
79 + });
80 + }
81 +
82 + function downloadUrl(url, callback) {
83 + var request = window.ActiveXObject ?
84 + new ActiveXObject('Microsoft.XMLHTTP') :
85 + new XMLHttpRequest;
86 +
87 + request.onreadystatechange = function() {
88 + if (request.readyState == 4) {
89 + request.onreadystatechange = doNothing;
90 + callback(request, request.status);
91 + }
92 + };
93 +
94 + request.open('GET', url, true);
95 + request.send(null);
96 + }
97 +
98 + function doNothing() {}
99 + </script>
100 + <script async defer
101 + src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDxV4OE9LULUMIYriVBLqR23YNGsZ_YgkI&callback=initMap">
102 + </script>
103 + </body>
104 +</html>