Giter Club home page Giter Club logo

laravel-weather's Introduction

Laravel Weather

Latest Version on Packagist Total Downloads tests

Description

This package allows you to fetch weather data from different weather providers

Installation

You can install the package via composer:

composer require vemcogroup/laravel-weather

The package will automatically register its service provider.

To publish the config file to config/weather.php run:

php artisan vendor:publish --provider="Vemcogroup\Weather\WeatherServiceProvider"

The default configuration can be seen here

Usage

At the moment this package support the following weather services, you can update WEATHER_PROVIDER to one of the following

Service Provider name Website Geocoding Remarks
Dark Sky darksky https://darksky.net Manual Deprecated, not able to acquire api key https://blog.darksky.net. Will continue to function until March 31st, 2023.
Weatherstack weatherstack https://weatherstack.com Auto For historical data a minimum Standard license is required. For forecast data a minimum Professional license is required.
WeatherKit weatherkit https://developer.apple.com/weatherkit/ Auto Needs an apple developer account.

For other weather services fill free to create an issue or make a Pull Request.

For Manual geocoding you need a Google geocode api key.
Acquire it here https://developers.google.com/maps/documentation/geocoding/start and insert it into your .env file.

GOOGLE_MAPS_GEOCODING_API_KEY= 

Request

Start by setting up your request

$request = (new Vemcogroup\Weather\Request('1 Infinite Loop, Cupertino, CA 95014, USA'));

By default, it caches the weather response for 24hrs (86.400sec), this can be changed by setting a second parameter to cache timeout (in seconds)

$request = (new Vemcogroup\Weather\Request('1 Infinite Loop, Cupertino, CA 95014, USA', 600));

Units
There two available unit types, default is Metric:

Metric (m): Vemcogroup\Weather\Providers\Provider::WEATHER_UNITS_METRIC
Fahrenheit (f): Vemcogroup\Weather\Providers\Provider::WEATHER_UNITS_FAHRENHEIT

To change the response units you can do the following:

$request->withUnits(Vemcogroup\Weather\Providers\Provider::WEATHER_UNITS_FAHRENHEIT);

Locale
To change the locale for descriptions, summaries and other texts in the response, do the following:

$request->withLocale('nl');

Locale need to be an 2-letter ISO Code of your preferred language.

Dates If you need to select the dates to get weather data for E.g for historical data, set the dates like this:

$request->withDates([$date, ...]);

All dates in the array need to Carbon objects.

Options
If you need to set any extra options based in your selected weather provider you can do the following:

$request->withOption('name', 'value');

Current weather and forecast

To get current weather and forecast response you can do this:

$weather = weather()->getForecast($request);

Weather response will always be a Collection of responses.
Forecast days depends on weather service provider.

To get current weather data:

$weather->first()->getCurrently(); // DataPoint

To get forecast you can take first element of response and get the forecast like this:

$weather->first()->getDaily()->getData(); // array

Afterward run through the array with represent each day of the forecast on a DataPoint object.

Historical

To get historical data you can do this:

$weather = weather()->getHistorical($request);

Remember to set dates on request.
Response will be a collection with keys representing the dates for historical data.

Response

To see what response data is available look into source code /src/Objects

laravel-weather's People

Contributors

mikkp17 avatar eldor avatar makije avatar danijelk avatar

Stargazers

Zaher Ghaibeh avatar Alan Wynn avatar Codelapan avatar Isaac Ongoma avatar Eyal Gantz avatar KKAME avatar Ali KARABAY avatar Jay Bardeleben avatar Jan Daryl Galbo avatar Alessio avatar  avatar Derek Lawrie avatar  avatar  avatar MatchTime - Formerly TennisPoint.com avatar chaoswey avatar  avatar Denis Veg avatar  avatar Roberto Gallea avatar MarcS avatar Cody avatar Dragan Mitić avatar Lakatos Tibor avatar Magno F. B. Biét avatar Alexssander Cusin avatar Ibrahim El monier avatar Benny Leonard Enrico Panggabean avatar Benoit VRIGNAUD avatar Sachit avatar Abdulrahman Asaad avatar Charlie Page avatar Christoph Vollmann avatar Kasper Hartwich avatar Patompong Savaengsuk avatar Lenix avatar Alexandre Almeida avatar  avatar Robert Boes avatar James Merrix avatar Md Minhazul Abadin avatar Mikkel Rasmussen avatar Paul Grant Truesdell, II avatar Atef Ben Ali avatar TiX avatar David Pella avatar Nick Zhang avatar Ryan Eby avatar Jesús Avelar avatar  avatar Jonathan Goode avatar Mr Hexagon avatar  avatar

Watchers

 avatar  avatar James Cloos avatar Eyal Gantz avatar Isaac Ongoma avatar

laravel-weather's Issues

Windy

Hallo, would it be possible to add Windy Api as a Weather Provider? I think it has forecast with the free api key, but it has to be rendered. Thanks in advance.

Exception

Undefined property: stdClass::$current

Historical data requests forces interval to 1

Hello. We started using this package recently and were attempting to create this URL for WeatherStack:

https://api.weatherstack.com/historical?query=25.7617,-80.1918&historical_date_start=2021-01-01&historical_date_end=2021-01-02&units=f&hourly=1&interval=24

As you can see we are trying to get historical data, with the interval set to interval=24. However when calling

weather()->getHistorical($request);

It forces the interval to change to interval=1. Seems to be coming from this line https://github.com/vemcogroup/laravel-weather/blob/master/src/Providers/Weatherstack.php#L53

Is there a way to override this somehow?

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.