GeocoderTrait.php 1007 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the Geocoder package.
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @license MIT License
  9. */
  10. namespace Geocoder;
  11. use Geocoder\Query\GeocodeQuery;
  12. use Geocoder\Query\ReverseQuery;
  13. /**
  14. * A trait that turns a Provider into a Geocoder.
  15. *
  16. * @author Tobias Nyholm <tobias.nyholm@gmail.com>
  17. */
  18. trait GeocoderTrait
  19. {
  20. abstract public function geocodeQuery(GeocodeQuery $query): Collection;
  21. abstract public function reverseQuery(ReverseQuery $query): Collection;
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function geocode(string $value): Collection
  26. {
  27. return $this->geocodeQuery(GeocodeQuery::create($value));
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function reverse(float $latitude, float $longitude): Collection
  33. {
  34. return $this->reverseQuery(ReverseQuery::fromCoordinates($latitude, $longitude));
  35. }
  36. }