-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap (2).html
154 lines (138 loc) · 4.38 KB
/
map (2).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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!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(42.3601, 71.0589);
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
});
}
});
console.log("codeAddress called");
}
$(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">
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 = (function() {
// var masterlist = [];
// function getCountries2Cities(callback) {
// $.ajax({
// method: 'GET',
// url: 'countries2cities.json',
// dataType: 'json',
// success: function(data) {
// for (var key in data) {
// if (data.hasOwnProperty(key)) {
// masterlist.push(key);
// for (k = 0; k < data[key].length; k++) {
// masterlist.push(data[key][k]);
// }
// }
// }
// callback(masterlist);
// }
// });
// }
// return {
// getMasterList: function() {
// getCountries2Cities(function(data){
// });
// return masterlist
// }
// }
// })();
var countriescitieslist;
var CountriesCitiesData = (function(){
var masterlist = [];
function getCountriesCities(callback) {
$.ajax({
method: 'GET',
url: 'countries2cities.json',
dataType: 'json',
success: function(data) {
for (var key in data) {
if (data.hasOwnProperty(key)) {
masterlist.push(key);
for (k = 0; k < data[key].length; k++) {
masterlist.push(data[key][k]);
}
}
}
callback(masterlist);
}
});
}
return {
getList: function() {
getCountriesCities(function(data){});
return masterlist
}
}
})();
countriescitieslist = CountriesCitiesData.getList();
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++) {
if (makeReadable(data.posts[i].locations[j]) in countriescitieslist) {
codeAddress(makeReadable(data.posts[i].locations[j]));
$("#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>