Coordinates.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Model;
  11. use Geocoder\Assert;
  12. /**
  13. * @author William Durand <william.durand1@gmail.com>
  14. */
  15. final class Coordinates
  16. {
  17. /**
  18. * @var float
  19. */
  20. private $latitude;
  21. /**
  22. * @var float
  23. */
  24. private $longitude;
  25. /**
  26. * @param float $latitude
  27. * @param float $longitude
  28. */
  29. public function __construct($latitude, $longitude)
  30. {
  31. Assert::notNull($latitude);
  32. Assert::notNull($longitude);
  33. $latitude = (float) $latitude;
  34. $longitude = (float) $longitude;
  35. Assert::latitude($latitude);
  36. Assert::longitude($longitude);
  37. $this->latitude = $latitude;
  38. $this->longitude = $longitude;
  39. }
  40. /**
  41. * Returns the latitude.
  42. *
  43. * @return float
  44. */
  45. public function getLatitude(): float
  46. {
  47. return $this->latitude;
  48. }
  49. /**
  50. * Returns the longitude.
  51. *
  52. * @return float
  53. */
  54. public function getLongitude(): float
  55. {
  56. return $this->longitude;
  57. }
  58. /**
  59. * Returns the coordinates as a tuple.
  60. *
  61. * @return array
  62. */
  63. public function toArray(): array
  64. {
  65. return [$this->getLongitude(), $this->getLatitude()];
  66. }
  67. }