Code Monkey home page Code Monkey logo

angular-weather's Introduction

angular-weather

Simple AngularJS project showing the weather, test project looking into afew different things.

Points of Interest

  • Browser base navigator.geolocation experiment
  • Yahoo GEO Encoding API
  • Yahoo Weather API
  • Responses can be viewing in JSON and pretty print formats
  • Simply Twitter Bootstrap Theme

Services

  • Yahoo GEO Encoding API as well Yahoo Weather API, see

    /app/services/yahooWeatherService.js

  • Browser/HTML GeoLocation services (If Exposed)

    /app/services/browserGeoService.js

Other Things TODO

  • Display Errors - Anguylar UI Alert

  • Local browser storage support

  • Keep track of previous search

  • Allow searches to be clickable to re-run queries

  • Angular UI integration?

  • Allow query based on city lookup?

  • Auto complete list of cities? - Where do I get this from?

  • Use route provider params to encode geolocation or city

  • Allow history of searches?

  • Namespace services and componenets? - Modules?

  • Unit test services

angular-weather's People

Contributors

jamesmorgan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

angular-weather's Issues

No service of yahoos-woeid-by-location

Hello James,

Your code is not working and I found the yahoos-woeid-by-location service is closed.

http://stackoverflow.com/questions/15784177/how-to-get-yahoos-woeid-by-location
In the above site, one recommended to use metwit weather API.
I modified some of you code and now it is working.

Regards,
Kim

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>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.