-
Notifications
You must be signed in to change notification settings - Fork 0
/
map (3).html
118 lines (107 loc) · 3.04 KB
/
map (3).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
<!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
});
}
});
}
$(document).ready(function() {
initialize();
});
</script>
</head>
<body>
<div id="map-canvas"></div>
<div id="locationsinfo">
<p style="font-weight: bold">LOCATIONS</p>
<div id="locations"></div>
</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 masterlist = [];
function getCountriesCities() {
$.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]);
}
}
}
InfoFromFeed.getData();
}
});
}
var InfoFromFeed = (function() {
function getInfoFromFeed() {
$.ajax({
method: 'GET',
url: 'feed.txt',
dataType: 'json',
success: function(data) {
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 (masterlist.indexOf(makeReadable(data.posts[i].locations[j])) > -1) {
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>");
}
}
}
}
}
}
});
}
return {
getData: function() {
getInfoFromFeed(function(data){});
}
}
})();
getCountriesCities();
</script>
</body>
</html>