定制 sircamp/google-map-form-type-builder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sircamp/google-map-form-type-builder

最新稳定版本:1.0

Composer 安装命令:

composer require sircamp/google-map-form-type-builder

包简介

A form buoilder for google maps and symfony

README 文档

README

Set latitude, longitude, street, postcode and city values on a form using Google Maps. The map allows you to search the place by a data that you have filled or by current location button. When a pin is placed or dragged on the map, the latitude longitude fields are updated.

Installation

This bundle is compatible with Symfony >= 2.1. Add the following to your composer.json:

    "sircamp/google-map-form-type-bundle": "dev-master"

Register the bundle in your app/AppKernel.php by adding this line in the bundles array:

    new Sircamp\GoogleMapFormTypeBundle\SircampGoogleMapFormTypeBundle(),

Remember to add the bundle on assetic field present in your configuration file ( config.yalm or others )

Add OhGoogleMapFormTypeBundle to assetic

# app/config/config.yml
# Assetic Configuration
assetic:
    bundles:        [ 'SircampGoogleMapFormTypeBundle' ]

Usage

This bundle contains a new FormType called GoogleMapType which can be used in your forms like so:

    $builder->add('address', 'sircamp_google_maps');

On your model you will have to process the latitude, longitude, street, city, postcode array

    
    use Symfony\Component\Validator\Constraints as Assert;
    use Sircamp\GoogleMapFormTypeBundle\Validator\Constraints as OhAssert;

    class MyEntity
    {
        // ... include your latitude,longitude,street,city,postacode fields here

   /**
    * @Assert\NotBlank()
    * @SircampAssert\Address()
    */
    public function getAddress()
    {
       return array('address' => array(
       'lat' => $this->latitude,
       'lng' => $this->longitude, 
       'street' => $this->street,
       'city' => $this->city, 
       'postcode'=>$this->postcode));
    }

    public function setAddress($address)
    {
       // die(var_dump($address,$address['address']['lat']));
       $this
          ->setCity($address['address']['city'])
          ->setPostcode($address['address']['postcode'])
          ->setStreet($address['address']['street'])
          ->setLatitude($address['address']['lat'])
          ->setLongitude($address['address']['lng']);
       
       return $this;
    }

  }

Include the twig template on your config.yalm for the layout. 
```yaml
    # your config.yml
    twig:
        form:
            resources:
                # This uses the default - you can put your own one here
                - 'SircampGoogleMapFormTypeBundle:Form:fields.html.twig'

If you are intending to override some of the elements in the template then you can do so by extending the default google_maps.html.twig. This example adds a callback to the javascript when a new map position is selected.

Credits

This librabry is based on the orignal made by

  • Ollie Harridge (ollietb)

统计信息

  • 总下载量: 51
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: CSS

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-01