diff --git a/src/Command/ImportKMLFileCommand.php b/src/Command/ImportKMLFileCommand.php index 4f378498..4d2e71a2 100644 --- a/src/Command/ImportKMLFileCommand.php +++ b/src/Command/ImportKMLFileCommand.php @@ -13,6 +13,8 @@ use App\Service\KMLFileImporter; class ImportKMLFileCommand extends Command { + protected $importer; + protected function configure() { $this->setName('supportedarea:import') diff --git a/src/Command/TestGeofenceCommand.php b/src/Command/TestGeofenceCommand.php new file mode 100644 index 00000000..1397f08f --- /dev/null +++ b/src/Command/TestGeofenceCommand.php @@ -0,0 +1,44 @@ +setName('test:geofence') + ->setDescription('Test geofence tracker service.') + ->setHelp('Test the geofence tracker service.') + ->addArgument('long', InputArgument::REQUIRED, 'Longitude') + ->addArgument('lat', InputArgument::REQUIRED, 'Latitude'); + } + + public function __construct(GeofenceTracker $geo) + { + $this->geo = $geo; + + parent::__construct(); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $long = $input->getArgument('long'); + $lat = $input->getArgument('lat'); + + if ($this->geo->isCovered($long, $lat)) + echo "In geofence\n"; + else + echo "NOT in geofence\n"; + } +} diff --git a/src/Service/GeofenceTracker.php b/src/Service/GeofenceTracker.php new file mode 100644 index 00000000..b2052e02 --- /dev/null +++ b/src/Service/GeofenceTracker.php @@ -0,0 +1,35 @@ +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; + } +}