-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp_map.html
87 lines (80 loc) · 2.51 KB
/
wp_map.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html >
<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>Wordpress map</title>
<style>
#map {
height: 400px;
width: 100%;
}
html, body {
height: 100%;
width: 65%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap()
{
var map = new google.maps.Map(document.getElementById('map'),
{
center: new google.maps.LatLng(20, 0),
zoom: 1
});
var infoWindow = new google.maps.InfoWindow;
downloadUrl('http://localhost/outputXML.php', function(data)
{
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem)
{
var id = markerElem.getAttribute('id');
var name = markerElem.getAttribute('name');
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));
var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = name
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));
var marker = new google.maps.Marker
({
map: map,
position: point,
});
marker.addListener('click', function()
{
infoWindow.setContent(infowincontent);
infoWindow.open(map, marker);
});
});
});
}
function downloadUrl(url, callback)
{
var request = 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>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAoaY4TIlQXDHyd5dkFrM5LLiAy9MqZMAA&callback=initMap">
</script>
</body>
</html>