-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatafromweb.html
167 lines (144 loc) · 4.68 KB
/
datafromweb.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
155
156
157
158
159
160
161
162
163
164
165
166
167
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Map My Feed </title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
.labels {
color: white;
background-color: blue;
font-family: "Lucida Grande", "Arial", sans-serif;
font-size: 10px;
text-align: center;
width: 30px;
white-space: nowrap;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript">
var geocoder;
var map;
var locations=[
'New York City',
'Los Angeles',
'Chicago',
'Houston',
'Philadelphia',
'Phoenix',
'San Diego',
'San Francisco',
'Indianapolis',
'Washington, D.C.']
var flickeringColors=[
'ff0000',
'80d926',
'00bfff',
'e6194d',
'df2020'
]
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: {lat: -28.024, lng: 140.887}
});
//Iterate Over the List of Locations and fetch the data
downloadDataFromWeb(locations[0],0)
}
function downloadDataFromWeb(cityCode,cityId){
console.log("Fetching Data from "+cityCode)
var url = "https://api.nytimes.com/svc/search/v2/articlesearch.json";
url += '?' + $.param({
'api-key': "edfc42f1b85b48e1aa8885835550beed",
'q':cityCode,
'fl': "headline,snippet,abstract,web_url,document_type",
'begin_date': "20161014",
'end_date': "20161014",
'sort': "newest"
});
$.ajax({
url: url,
method: 'GET',
}).done(function(result) {
startParsingData(result.response.docs,cityCode)
if(cityId+1<locations.length){
setTimeout(function() {
downloadDataFromWeb(locations[cityId+1],cityId+1)}, 1000)
}
// setTimeout(),1000)
else
console.log("Boom !! And Everything is Over ")
}).fail(function(err) {
console.log("Oopsies !! Error "+cityCode)
console.log(err)
throw err;
});
}
function startParsingData(dataNode,cityCode){
console.log(dataNode)
codeAddress(dataNode,cityCode,dataNode.length)
}
function openNewsDetail(dataNode){
var web_urls=[]
for(i=0;i<dataNode.length;i++){
web_urls.push(dataNode[i].web_url)
}
console.log("Mapping The Web URL ")
console.log(web_urls)
}
function codeAddress(dataNode,addressinWords,numberOfResults) {
console.log(dataNode)
var dataCount=numberOfResults>10?'10+':numberOfResults
var infowindow = new google.maps.InfoWindow();
content= document.createElement('a');
content.setAttribute('href','#');
content.appendChild(document.createTextNode(addressinWords+' '+dataCount+' News'));
google.maps.event.addDomListener(content,'click',
function(){openNewsDetail(dataNode);})
infowindow.setContent(content);
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address':addressinWords}, function(results, status) {
if (status == 'OK') {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' +dataCount + '|FF0000|000000',
visible: true});
marker.setMap(map)
setInterval(function() {
console.log("Map Index "+Math.floor(Math.random() * (4 - 0) + 0));
var markerUrl='http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' +dataCount +'|'+flickeringColors[Math.floor(Math.random() * (4 - 0) + 0)]+'|000000';
marker.setIcon(markerUrl)
},2000)
marker.addListener('click', function() {
infowindow.open(map, marker);
infowindow.addListener('click',function(){
console.log("Okay !! Some Serious Data Displaying to be Done !!")
})
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
</script>
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js">
</script>
<script async defer src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/src/markerwithlabel.js&callback=markerLoaded"></script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBtP-yPXvls7KXyrqXzgIeKRIT-Wbp7Rao&callback=initMap">
</script>
<script src="https://cdn.rawgit.com/googlemaps/v3-utility-library/markermanager/1.2/markermanager.js"></script>
</html>