-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
149 lines (118 loc) · 4.63 KB
/
script.js
File metadata and controls
149 lines (118 loc) · 4.63 KB
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
/*global google $*/
function onClientLoad() {
gapi.client.load('youtube', 'v3', onYoutubeApiLoad);
console.log("youtube loaded");
}
function onYoutubeApiLoad() {
gapi.client.setApiKey("AIzaSyCzVOUqO_DSfgQpbCI_EE12KkOKoqTQC_4");
console.log("api key set");
}
var searchBox;
function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: -33.8688,
lng: 151.2195
},
zoom: 13,
mapTypeId: 'roadmap'
});
// Create the search box and link it to the UI element.
var input = document.getElementById('city-input');
searchBox = new google.maps.places.SearchBox(input);
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});
var markers = [];
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();
if ($(".title").hasClass("invisible")){
$("#video_header").append(places[0].name);
$("#image_header").append(places[0].name);
$(".title").removeClass("invisible");
}else{
$("#image_header").html("Pictures of " + places[0].name);
$("#video_header").html("Videos related to " + places[0].name);
}
//console.log(places);
if (places.length == 0) {
return;
}
// Clear out the old markers.
markers.forEach(function(marker) {
marker.setMap(null);
});
markers = [];
// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
updatePhotos(place);
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};
// Create a marker for each place.
markers.push(new google.maps.Marker({
map: map,
icon: icon,
title: place.name,
position: place.geometry.location
}));
if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
}
else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
searchVideos(places[0].name);
});
function updatePhotos(place) {
$("#photos").html("");
for (var i = 0; i < place.photos.length; i++) {
var url = place.photos[i].getUrl({
"maxWidth": 500,
"maxHeight": 500
});
$("#photos").append("<img class='image-fluid' src=" + url + " />");
}
}
function searchVideos(searchWord) {
var request = gapi.client.youtube.search.list({
part: 'snippet',
q: searchWord
});
request.execute(onSearchResponse);
}
function onSearchResponse(response) {
$("#youtube").html("");
console.log(response);
for (var i = 0; i < response.items.length; i++) {
console.log("appending...");
//$("#youtube").append("<div class='video-container'><div class='embed-responsive embed-responsive-16by9 video-embed'><iframe class='embed-responsive-item' width='420' height='315' src='https://www.youtube.com/embed/"+ response.items[i].id.videoId + "'></iframe></div></div>");
$("#youtube").append("<div class='video-container'><div class='video-wrapper embed-responsive embed-responsive-16by9'><div class='youtube' id='" + response.items[i].id.videoId + "' data-params='modestbranding=1&showinfo=0&controls=0&vq=hd720'></div></div></div>");
}
var tag = document.createElement('script');
tag.src = "video.js";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
// function addInitValue(){
// }
function addHeading(place) {
$("#video_header").append(place);
}
}
// Google Map API KEY --> AIzaSyDLeay - 3 D4F8f2RnSTncDkF5tOxm0naI_4