-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
120 lines (106 loc) · 3.43 KB
/
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Map</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng
}
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
console.log("geocoder initialized");
}
function codeAddress(address) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
});
}
$(document).ready(function() {
initialize();
});
</script>
</head>
<body>
<div id="locationsinfo">
<p style="font-weight: bold">LOCATIONS</p>
<div id="locations"></div>
</div>
<div id="map-canvas"></div>
<script type="text/javascript">
var masterlist = [];
function makeReadable(str) {
if (str == "U.S.") {
return "United States";
}
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
var InfoFromFeed = new XMLHttpRequest();
var url = "feed.txt";
InfoFromFeed.onreadystatechange = function() {
if (InfoFromFeed.readyState == 4 && InfoFromFeed.status == 200) {
var data = JSON.parse(InfoFromFeed.responseText);
var Countries2Cities = new XMLHttpRequest();
var url = "countries2cities.json";
Countries2Cities.onreadystatechange = function() {
if (Countries2Cities.readyState == 4 && Countries2Cities.status == 200) {
result = JSON.parse(Countries2Cities.responseText);
var list = []
for (var key in result) {
if (result.hasOwnProperty(key)) {
list.push(key);
for (k = 0; k < result[key].length; k++) {
list.push(result[key][k]);
}
}
}
masterlist = list;
}
}
Countries2Cities.open("GET", url, true);
Countries2Cities.send();
for (i = 0; i < data.posts.length; i++) {
if (data.posts[i].locations.length != 0) {
var ul = document.createElement("ul");
ul.id = i.toString();
$("#locations").append(ul);
$("#locations #" + ul.id).append("<li style='font-weight: bold'>" + data.posts[i].title + "</li>");
for (j = 0; j < data.posts[i].locations.length; j++) {
codeAddress(makeReadable(data.posts[i].locations[j]));
if (makeReadable(data.posts[i].locations[j]) in masterlist) {
appendtolocations = true;
}
else {
appendtolocations = false;
}
if (appendtolocations) {
$("#locations #" + ul.id).append("<li>" + makeReadable(data.posts[i].locations[j]) + "</li>");
if (j == data.posts[i].locations.length - 1) {
$("#locations #" + ul.id).append("<br>");
}
}
}
}
}
}
}
InfoFromFeed.open("GET", url, true);
InfoFromFeed.send();
</script>
</body>
</html>