|
1 | | -# angular-openweathermap-api-factory |
2 | | -AngularJS Factory for OpenWeatherMap JSON REST API requests |
| 1 | +**angular-openweathermap-api-factory** is an angularjs module with a openweathermap api factory. |
| 2 | + |
| 3 | +Author: Jonathan Hornung ([JohnnyTheTank](https://github.com/JohnnyTheTank)) |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +1. Install via [bower](http://bower.io/) : |
| 8 | + 1. `bower install --save angular-openweathermap-api-factory` |
| 9 | +2. Add `jtt_openweathermap` to your application's module dependencies. |
| 10 | +3. Include dependencies in your HTML. |
| 11 | + 1. When using bower: |
| 12 | + |
| 13 | + ```html |
| 14 | + <script src="bower_components/angular/angular.js"></script> |
| 15 | + <script src="bower_components/angular-openweathermap-api-factory/src/angular-openweathermap-api-factory.js"></script> |
| 16 | + ``` |
| 17 | + |
| 18 | +4. Use the factory `openweathermapFactory`. |
| 19 | + |
| 20 | + |
| 21 | +### factory methods |
| 22 | + |
| 23 | +#### weather from city by name |
| 24 | +```js |
| 25 | +// docs: http://openweathermap.org/current#name |
| 26 | +openweathermapFactory.getWeatherFromCitySearchByName({ |
| 27 | + q:"<CITY_NAME>,<COUNTRY_CODE>", //city name and country code divided by comma, use ISO 3166 country codes eg "London,uk" |
| 28 | + lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi |
| 29 | + units:"<UNITS>", // (optinal) http://openweathermap.org/current#data |
| 30 | + type:"<TYPE>", // (optional) 'like' = close result, 'accurate' = accurate result |
| 31 | + appid:"<APP_ID>" |
| 32 | +}).success(function(_data){ |
| 33 | + //on success |
| 34 | +}).error(function (_data) { |
| 35 | + //on error |
| 36 | +}); |
| 37 | +``` |
| 38 | + |
| 39 | +#### weather from city by id |
| 40 | +```js |
| 41 | +// docs: http://openweathermap.org/current#cityid |
| 42 | +openweathermapFactory.getWeatherFromCityById({ |
| 43 | + id:"<CITY_ID>", //List of city ID can be downloaded here http://bulk.openweathermap.org/sample/city.list.json.gz |
| 44 | + lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi |
| 45 | + units:"<UNITS>", // (optinal) http://openweathermap.org/current#data |
| 46 | + appid:"<APP_ID>" |
| 47 | +}).success(function(_data){ |
| 48 | + //on success |
| 49 | +}).error(function (_data) { |
| 50 | + //on error |
| 51 | +}); |
| 52 | +``` |
| 53 | + |
| 54 | +#### weather from group of cities by id |
| 55 | +```js |
| 56 | +// docs: http://openweathermap.org/current#severalid |
| 57 | +openweathermapFactory.getWeatherFromGroupOfCitiesById({ |
| 58 | + id:"<CITY_ID>,<CITY_ID>,<CITY_ID>,...", //List of city ID can be downloaded here http://bulk.openweathermap.org/sample/city.list.json.gz |
| 59 | + lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi |
| 60 | + units:"<UNITS>", // (optinal) http://openweathermap.org/current#data |
| 61 | + appid:"<APP_ID>" |
| 62 | +}).success(function(_data){ |
| 63 | + //on success |
| 64 | +}).error(function (_data) { |
| 65 | + //on error |
| 66 | +}); |
| 67 | +``` |
| 68 | + |
| 69 | +#### weather from location by coordinates |
| 70 | +```js |
| 71 | +// docs: http://openweathermap.org/current#geo |
| 72 | +openweathermapFactory.getWeatherFromLocationByCoordinates({ |
| 73 | + lat:"<LAT>", |
| 74 | + lon:"<LONG>", |
| 75 | + lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi |
| 76 | + units:"<UNITS>", // (optinal) http://openweathermap.org/current#data |
| 77 | + appid:"<APP_ID>" |
| 78 | +}).success(function(_data){ |
| 79 | + //on success |
| 80 | +}).error(function (_data) { |
| 81 | + //on error |
| 82 | +}); |
| 83 | +``` |
| 84 | + |
| 85 | +#### weather from location by zipcode |
| 86 | +```js |
| 87 | +// docs: http://openweathermap.org/current#zip |
| 88 | +openweathermapFactory.getWeatherFromLocationByCoordinates({ |
| 89 | + zip:"<ZIPCODE>,<COUNTRY_CODE>", //use ISO 3166 country codes |
| 90 | + lang:"<LANGUAGE>", // http://openweathermap.org/current#multi |
| 91 | + units:"<UNITS>", // (optinal) http://openweathermap.org/current#data |
| 92 | + appid:"<APP_ID>" |
| 93 | +}).success(function(_data){ |
| 94 | + //on success |
| 95 | +}).error(function (_data) { |
| 96 | + //on error |
| 97 | +}); |
| 98 | +``` |
| 99 | + |
| 100 | +## OpenWeatherMap JSON API |
| 101 | + |
| 102 | +* docs: http://openweathermap.org/api |
| 103 | + |
| 104 | +## License |
| 105 | + |
| 106 | +MIT |
0 commit comments