resq/src/Service/GeofenceTracker.php

35 lines
815 B
PHP

<?php
namespace App\Service;
use App\Entity\SupportedArea;
use Doctrine\ORM\EntityManagerInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
class GeofenceTracker
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function isCovered($long, $lat)
{
// see if the point is in any of the polygons
$query = $this->em->createQuery('SELECT count(s) from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true')
->setParameter('long', $long)
->setParameter('lat', $lat);
// number of polygons that contain the point
$count = $query->getSingleScalarResult();
if ($count > 0)
return true;
return false;
}
}