-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherController.js
48 lines (37 loc) · 1.78 KB
/
weatherController.js
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
var app = angular.module('weatherApp',[]);
app.controller('weatherController', function($scope,$http){
$scope.weatherSearch = function(){
var openWeatherMapUrl = "http://api.openweathermap.org/data/2.5/weather?zip=" + $scope.zipcode + "&appid=87221180cc840254c9be2cf5f2dedddc";
console.log(openWeatherMapUrl);
console.log($scope.zipcode);
$http.get(openWeatherMapUrl)
.then(function(data){
$scope.weather = data.data.weather[0];
$scope.icon = "http://openweathermap.org/img/w/" + $scope.weather.icon + ".png";
$scope.main = data.data.main;
$scope.fTemp = ($scope.main.temp *(9/5) - 459.67).toFixed(1) ;
$scope.cTemp = ($scope.main.temp - 273).toFixed(1);
$scope.localCity = data.data.name;
$scope.country = data.data.sys.country;
})
};
var localLocation = "http://ip-api.com/json";
$http.get(localLocation)
.then(function(data){
$scope.localCity = data.data.city;
$scope.country = data.data.countryCode;
var zip = data.data.zip;
console.log( $scope.localCity);
var openWeatherMapUrlLocal = "http://api.openweathermap.org/data/2.5/weather?zip=" + zip + "&appid=87221180cc840254c9be2cf5f2dedddc";
console.log( openWeatherMapUrlLocal);
$http.get(openWeatherMapUrlLocal)
.then(function(data){
$scope.weather = data.data.weather[0];
$scope.icon = "http://openweathermap.org/img/w/" + $scope.weather.icon + ".png";
$scope.main = data.data.main;
$scope.fTemp = ($scope.main.temp *(9/5) - 459.67).toFixed(1) ;
$scope.cTemp = ($scope.main.temp - 273).toFixed(1);
$scope.name = data.data.name;
})
})
});