58 lines
1.1 KiB
PHP
58 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pcm\GeocodeBundle\Entity\Trait;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* Allows an entity to be mapped via latitude and longitude coordinates
|
|
*
|
|
* Use MappableInterface
|
|
*
|
|
* @package Pcm\GeocodeBundle
|
|
*/
|
|
trait MappableTrait
|
|
{
|
|
#[ORM\Column(type: 'decimal', precision: 10, scale: 6, nullable: true)]
|
|
private ?float $latitude = null;
|
|
|
|
#[ORM\Column(type: 'decimal', precision: 10, scale: 6, nullable: true)]
|
|
private ?float $longitude = null;
|
|
|
|
public function getLatitude(): ?float
|
|
{
|
|
return $this->latitude;
|
|
}
|
|
|
|
public function getLongitude(): ?float
|
|
{
|
|
return $this->longitude;
|
|
}
|
|
|
|
public function setLatitude(float $lat): self
|
|
{
|
|
$this->latitude = $lat;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setLongitude(float $lon): self
|
|
{
|
|
$this->longitude = $lon;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Returns true if both latitude and longitude have been set
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isGeocoded(): bool
|
|
{
|
|
return null !== $this->getLatitude() && null !== $this->getLongitude();
|
|
}
|
|
}
|