Save cooridnates as GeoJSON in database
This commit is contained in:
parent
4656be5a32
commit
ddb815d1b4
5 changed files with 130 additions and 2 deletions
|
@ -13,6 +13,8 @@ use App\Service\DistanceCalculator;
|
|||
use App\Service\OfferPhotoHelper;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Location\Coordinate;
|
||||
use Location\Formatter\Coordinate\GeoJSON;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -38,7 +40,7 @@ class OfferController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/new', name: 'new_offer')]
|
||||
public function newOffer(Request $request, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
|
||||
public function newOffer(Request $request, string $photoDir, OfferPhotoHelper $offerPhotoHelper, PlzToCoordinate $plzconverter): Response
|
||||
{
|
||||
$offer = new Offering();
|
||||
$form = $this->createForm(OfferingFormType::class, $offer);
|
||||
|
@ -50,6 +52,11 @@ class OfferController extends AbstractController
|
|||
$offer->setByUser($user);
|
||||
$offer->setCreatedAt(new \DateTime());
|
||||
|
||||
if ($offerPlz = $form['zipCode']->getData()) {
|
||||
$coordinate = $plzconverter->convertPlzToCoordinate($offerPlz);
|
||||
$offer->setCoordinate($coordinate->format(new GeoJSON()));
|
||||
}
|
||||
|
||||
if ($photo = $form['photo']->getData()) {
|
||||
$offerPhotoHelper->uploadOfferPhoto($photoDir, $photo, $offer);
|
||||
}
|
||||
|
@ -81,7 +88,7 @@ class OfferController extends AbstractController
|
|||
|
||||
if (isset($userPlz))
|
||||
{
|
||||
$distance = $distanceCalculator->calculateDistance($plzconverter->getCoordinates($offerPlz), $plzconverter->getCoordinates($userPlz));
|
||||
$distance = $distanceCalculator->calculateDistance($plzconverter->convertPlzToCoordinate($offerPlz), $plzconverter->convertPlzToCoordinate($userPlz));
|
||||
}
|
||||
|
||||
return $this->render('app/offer.html.twig', [
|
||||
|
|
Reference in a new issue