Book Image

Extending Symfony2 Web Application Framework

By : Sebastien Armand
Book Image

Extending Symfony2 Web Application Framework

By: Sebastien Armand

Overview of this book

Table of Contents (13 chapters)

An input for geographical coordinates


Our special field will use Google Maps and this will be the only part visible to the user. To achieve all this, since this is a rather complex widget, we will need all of the following four elements:

  • A Coordinate class to hold our information

  • A form type

  • A Twig template

  • A data transformer

In most cases, you will not need all of these. You have probably already defined form types without any of the other elements.

The Google Maps integration will be done by an external bundle available at https://github.com/egeloen/IvoryGoogleMapBundle.

The Coordinate class is quite straightforward and will not change much, so let's have a quick look at it in the following code:

namespace Khepin\BookBundle\Geo;

use Ivory\GoogleMapBundle\Entity\Coordinate as GMapsCoordinate;

class Coordinate
{
    private $latitude;

    private $longitude;

    public function __construct($latitude = null, $longitude = null)
    {
        $this->latitude = $latitude;
        $this->longitude...