The following function throws an error when called in document ready with jQuery:
searchCity:function(){
var map = this.map,
markers = [],
input = document.getElementById('pac-input'),
dataTable;
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
var searchBox = new google.maps.places.SearchBox(input);
google.maps.event.addListener(searchBox, 'places_changed', function() {
var places = searchBox.getPlaces(),
apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
url = 'https://api.forecast.io/forecast/',
lati = places[0].geometry.location.B,
longi = places[0].geometry.location.k,
data,
city = $('.city'),
summary = $('.summary');
console.log(places);
$.getJSON(url + apiKey + "/" + lati + "," + longi + "?callback=?", function(data) {
console.log(data);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('string', 'hours');
dataTable.addColumn('number', 'temperature');
for(var i=0; i<data.daily.data.length; i++){
// dataTable.addColumn({type: 'string', role: 'annotation'});
dataTable.addRows([
['0'+i, data.daily.data[i].temperatureMax]
]);
}
// Load the Visualization API and the piechart package.
// google.load('visualization', '1.0', {'packages':['corechart'], callback: weatherAPP.generateGraph});
var options = { tooltip: {isHtml: true}};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(dataTable, options);
city.html('');
setTimeout( function(){
weatherAPP.slideToCloseSearch();
}, 500 );
city.html('').html(places[0].formatted_address);
summary.html('').html(data.daily.summary);
if(data.currently.icon = 'clear-day'){
$('.iconHolder').addClass('icon-sun');
}
else if(data.currently.icon = 'rain'){
$('iconHolder').addClass('icon-rainy');
}
$('.temperature').html(data.currently.temperature+ ' <span>F</span>');
weatherAPP.generateRainVisualEffect();
});
if (places.length == 0) {
return;
}
for (var i = 0, marker; marker = markers[i]; i++) {
marker.setMap(null);
}
// For each place, get the icon, place name, and location.
var bounds = new google.maps.LatLngBounds();
for (var i = 0, place; place = places[i]; i++) {
var image = {
url: 'pin.png'
};
var marker = new google.maps.Marker({
map: map,
icon: image,
title: place.name,
position: place.geometry.location
});
markers.push(marker);
bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
}); // places_changed
// Bias the SearchBox results towards places that are within the bounds of the
// current map's viewport.
google.maps.event.addListener(map, 'bounds_changed', function() {
map.setZoom(6);
var bounds = map.getBounds();
searchBox.setBounds(bounds);
});
},
$(document).ready(function(){
weatherAPP.displayTime();
weatherAPP.generateMap();
$('.boom').on('click', function(){
if(mainWrapper.hasClass(animateLeft)){
weatherAPP.slideToCloseSearch();
}else{
weatherAPP.slideToSearch();
}
});
weatherAPP.searchCity();
});
ERROR: Cannot read property 'DataTable' of undefined