GoogleMapType
最初に をサービスとして app/config.yml
ファイルに定義しました。
services:
# ...
oh.GoogleMapFormType.form.type.googlemapformtype:
class: Oh\GoogleMapFormTypeBundle\Form\Type\GoogleMapType
tags:
- { name: form.type, alias: oh_google_maps }
私は Symfony2 にちょっと慣れていないので、何らかの理由でエイリアスがoh_google_maps
.
次に、Entity クラスに緯度と経度を格納するためのフィールドと関数を設定します。
private $latlng;
private $latitude;
private $longitude;
public function setLatlng($latlng)
{
$this->latlng = $latlng;
$this->latitude = $latlng['lat'];
$this->longitude = $latlng['lng'];
return $this;
}
/**
* @Assert\NotBlank()
* @OhAssert\LatLng()
*/
public function getLatLng()
{
return array('lat' => $this->latitude,'lng' => $this->longitude);
}
最後に、カスタム Sonata Admin クラスのconfigureFormFields
関数で:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
//...
->add('latlng', 'oh_google_maps', array());
}