This package uses geolocation to determine several properties around the sun position.
This package is a fork of Spatie/Sun
You can install the package via composer:
composer require bakame-php/geolocation
To instantiate the Bakame\Geolocation\Geolocation
class you need to use one of the following named constructor.
use Bakame\Geolocation\Geolocation;
//Brussels coordinates and GeoHash
$bxLatitude = 50.85045;
$bxLongitude = 4.3487805;
$bxGeohash = 'u1516cn9mfvv';
$location = GeoLocation::fromCoordinates($bxLatitude, $bxLongitude);
$location = Geolocation::fromGeoHash($bxGeohash);
On failed instantiation a Bakame\Geolocation\CanNotGenerateGeolocation
exception is thrown.
- Latitudes below
-90.0
or above90.0
degrees are capped, not wrapped. - Longitudes below
-180.0
or above180.0
degrees are wrapped.
Because the package is using the Geotools library, you can use other coordinates representation to instantiate a new object.
use Bakame\Geolocation\Geolocation;
use League\Geotools\Coordinate\Coordinate;
$bxDegrees = '50°51\'1.62"N, 4°20\'55.61"E';
$geoCoordinate = new Coordinate($bxDegrees);
$location = GeoLocation::fromGeotools($geoCoordinate);
You can get the time of the zenith.
$location->zenith(); // returns an instance of \DateTimeImmutable
You can get the time of the zenith on a specific date by passing an object which implements DateTimeInterface
to zenith
If the object extends DateTimeImmutable
the return object will be of the same type.
$carbon = CarbonImmutable::now();
$location->zenith($carbon); // returns an instance of \Carbon\CarbonImmutable
You can get the time of the sunrise.
$location->sunrise(); // returns an instance of \DateTimeImmutable
You can get the time of the sunrise on a specific date by passing an object which implements DateTimeInterface
to sunrise
If the object extends DateTimeImmutable
the return object will be of the same type.
$carbon = CarbonImmutable::now();
$location->sunrise($carbon); // returns an instance of \Carbon\CarbonImmutable
If no sunrise information is available for a specific geolocation null
is returned.
You can get the time of the sunset.
$location->sunset(); // returns an instance of \DateTimeImmutable
You can get the time of the sunset on a specific date by passing an object which implements DateTimeInterface
to sunset
If the object extends DateTimeImmutable
the return object will be of the same type.
$carbon = CarbonImmutable::now();
$location->sunset($carbon); // returns an instance of \Carbon\CarbonImmutable
If no sunset information is available for a specific geolocation null
is returned.
This is how you can determine if the sun is up:
$location->isSunUp(); // returns a boolean
You can get determine if the sun is up at a specific moment by passing an instance of DateTimeInterface
to sunIsUp
$carbon = Carbon::now();
$location->sunIsUp($carbon); // returns a boolean
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.