Your code is not working and I found the yahoos-woeid-by-location service is closed.
diff --git a/app/controllers.js b/app/controllers.js
index b985ada..822cd0e 100644
--- a/app/controllers.js
+++ b/app/controllers.js
@@ -1,10 +1,9 @@
app.controller('MainContentController',
- function MainContentController($scope, $rootScope, $log, BrowserGeoService, YahooWeatherService) {
+ function MainContentController($scope, $rootScope, $log, BrowserGeoService, MetwitWeatherService) {
$scope.currentGeoPosition = null;
- $scope.currentWOEIDData = null;
- $scope.currentWeatherForWoeid = null;
+ $scope.currentWeather = null;
$scope.lastError = "";
$scope.showWoeidJson = false;
$scope.showForecastJson = false;
@@ -17,32 +16,19 @@ app.controller('MainContentController',
$scope.showWoeidJson = false;
$scope.showForecastJson = false;
$scope.currentGeoPosition = null;
- $scope.currentWOEIDData = null;
- $scope.currentWeatherForWoeid = null;
+ $scope.currentWeather = null;
$scope.lastError = "";
$scope.init();
}
- $scope.getWeatherForWOEID = function() {
- YahooWeatherService.getWeatherForWOEID($scope.currentWOEIDData.ResultSet.Results[0].woeid,
+ $scope.getWeather = function() {
+ MetwitWeatherService.getWeather($scope.currentGeoPosition,
function(data){
$log.info("Success : " + data);
- $scope.currentWeatherForWoeid = data;
+ $scope.currentWeather = data;
},
function(status){
- $scope.currentWeatherForWoeid = null;
- $log.info("Failure : " + status);
- });
- }
-
- $scope.lookupWOEIDGeoPosition = function() {
- YahooWeatherService.getWOEID($scope.currentGeoPosition,
- function(data){
- $log.info("Success : " + data);
- $scope.currentWOEIDData = data;
- },
- function(status){
- $scope.currentWOEIDData = null;
+ $scope.currentWeather = null;
$log.info("Failure : " + status);
});
}
diff --git a/app/services/metwitWeatherService.js b/app/services/metwitWeatherService.js
new file mode 100644
index 0000000..9b0ab3e
--- /dev/null
+++ b/app/services/metwitWeatherService.js
@@ -0,0 +1,22 @@
+app.service('MetwitWeatherService', function ($rootScope, $http, $log) {
+ var self = this;
+
+ // Metwit Weather API vars
+ var FORECAST_ENDPOINT = "https://api.metwit.com/v2/weather/?";
+
+
+ // https://api.metwit.com/v2/weather/?location_lat=45.45&location_lng=9.18
+ self.getWeather = function(position, successCallback, failureCallback) {
+ var endPoint = FORECAST_ENDPOINT + "location_lat=" + position.latitude + "&" +
+ "location_lng=" + position.longitude;
+ $log.info("End point = " + endPoint);
+ $http.get(endPoint)
+ .success(function(data, status, headers, config) {
+ successCallback(data);
+ })
+ .error(function(data, status, headers, config) {
+ failureCallback(status);
+ });
+ }
+
+});
diff --git a/app/services/yahooWeatherService.js b/app/services/yahooWeatherService.js
deleted file mode 100644
index f15f7eb..0000000
--- a/app/services/yahooWeatherService.js
+++ /dev/null
@@ -1,46 +0,0 @@
-app.service('YahooWeatherService', function YahooWeatherService($rootScope, $http, $log) {
- var self = this;
-
- // Yahoo WOEID Geo Lookup API vars
- var GEOCODE_ENDPOINT = "http://where.yahooapis.com/geocode";
-
- var YAHOO_GEO_APP_ID = "v6wFWp30";
- var APP_ID = "&appid=" + YAHOO_GEO_APP_ID;
- var LOCATION = "?location=";
- var FLAGS = "&flags=J&gflags=R";
-
- //http://query.yahooapis.com/v1/public/yql?q=select item from weather.forecast where location="48907"&format=json
-
- // Yahoo Weather API vars
- var FORECAST_ENDPOINT = "http://query.yahooapis.com/v1/public/yql?q=";
-
- var FORECAST_YQL_OPEN = "select * from weather.forecast where woeid='";
- var FORECAST_YQL_CLOSE = "'&format=json";
-
- self.getWOEID = function(position, successCallback, failureCallback) {
- // This would be so much nicer in coffeescript!
- var endPoint = GEOCODE_ENDPOINT + LOCATION + position.latitude + "," + position.longitude + FLAGS + APP_ID;
- $log.info("End point = " + endPoint);
-
- $http.get(endPoint)
- .success(function(data, status, headers, config) {
- successCallback(data);
- })
- .error(function(data, status, headers, config) {
- failureCallback(status);
- });
- }
-
- self.getWeatherForWOEID = function(woeid, successCallback, failureCallback) {
- var endPoint = FORECAST_ENDPOINT + FORECAST_YQL_OPEN + woeid + FORECAST_YQL_CLOSE;
- $log.info("End point = " + endPoint);
- $http.get(endPoint)
- .success(function(data, status, headers, config) {
- successCallback(data);
- })
- .error(function(data, status, headers, config) {
- failureCallback(status);
- });
- }
-
-});
diff --git a/index.html b/index.html
index 09aa478..dc587e9 100644
--- a/index.html
+++ b/index.html
@@ -36,8 +36,8 @@
<div class="span12">
<div class="btn-group">
- <button class="btn" ng-click="lookupWOEIDGeoPosition()">Get WOEID Geo Location</button>
- <button class="btn" ng-click="getWeatherForWOEID()" ng-hide="currentWOEIDData == null">Get Weather For WOEID</button>
+ <!--button class="btn" ng-click="lookupWOEIDGeoPosition()">Get WOEID Geo Location</button-->
+ <button class="btn" ng-click="getWeather()">Get Weather</button>
</div>
<div class="btn-group">
@@ -51,7 +51,7 @@
<div class="row">
- <div class="span6">
+ <!--div class="span6">
<div ng-show="currentWOEIDData != null">
<h5> WEOID Details </h5>
woeid : {{ currentWOEIDData.ResultSet.Results[0].woeid }} <br />
@@ -64,14 +64,14 @@
<button class="btbtn btn-linkn" ng-click="showWoeidJson = true">View JSON Response</button>
</div>
- </div>
+ </div-->
<div class="span6">
- <div ng-show="currentWeatherForWoeid != null">
+ <div ng-show="currentWeather != null">
<h5> Weather Details </h5>
- Forecast Today: <pre> {{ currentWeatherForWoeid.query.results.channel.item.forecast[0] }} </pre>
+ Forecast Today: <pre> {{ currentWeather.objects[0].weather.status }} </pre>
<br />
- Forecast Tomo: <pre> {{ currentWeatherForWoeid.query.results.channel.item.forecast[1] }} </pre>
+ Forecast Tomo: <pre> {{ currentWeather.objects[1].weather.status }} </pre>
<button class="btbtn btn-linkn" ng-click="showForecastJson = true">View JSON Response</button>
@@ -84,15 +84,15 @@
<div class="row">
- <div class="span6">
+ <!--div class="span6">
<div ng-show="currentWOEIDData != null && showWoeidJson == true">
<pre> {{ currentWOEIDData | json}} </pre>
</div>
- </div>
+ </div-->
<div class="span6">
- <div ng-show="currentWeatherForWoeid != null && showForecastJson == true">
- <pre> {{ currentWeatherForWoeid | json}} </pre>
+ <div ng-show="currentWeather != null && showForecastJson == true">
+ <pre> {{ currentWeather | json}} </pre>
</div>
</div>
@@ -108,7 +108,7 @@
<script src="app/controllers.js" type="text/javascript" ></script>
<script src="app/directives.js" type="text/javascript" ></script>
<script src="app/services/browserGeoService.js" type="text/javascript" ></script>
- <script src="app/services/yahooWeatherService.js" type="text/javascript" ></script>
+ <script src="app/services/metwitWeatherService.js" type="text/javascript" ></script>
</body>
</html>