cyberjaw/google-maps-bundle

安装次数: 9,058

依赖: 0

推荐者: 0

安全: 0

星标: 1

关注者: 0

分支: 1

公开问题: 1

语言:JavaScript

类型:symfony-bundle

1.1.0 2017-07-03 11:28 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:11:06 UTC


README

用于在您的表单中使用谷歌地图的Symfony组件

安装

此组件与Symfony >= 2.8 兼容

composer require cyberjaw/google-maps-bundle

入门

首先在您的 AppKernel.php 文件中注册组件

// app/AppKernel.php
  
$bundles = array(
    //...
    new CyberJaw\GoogleMapsBundle\GoogleMapsBundle()
    );

要启用模板并设置您的谷歌地图API密钥,请将以下内容添加到您的 config.yml 文件中。

# app/config/config.yml
## Twig Configuration
 
twig:
    form_themes:
        - 'GoogleMapsBundle:Form:google_maps_layout.html.twig'
        
google_maps:
    api_key: 'YOUR_API_KEY'

如果安装后未安装资产,请运行

//Symfony 2.8
    php app/console assets:install
    
//Symfony 3.*
    php bin/console assets:install

用法

此组件包含一个名为 GoogleMapType 的新表单类型,您可以在表单中使用它,如下所示

构建表单

use CyberJaw\GoogleMapsBundle\Form\Type\GoogleMapsType;
    
$builder->add('googleMaps', GoogleMapsType::class);

实体属性

class GoogleMaps
{
    protected $latitude;
    
    protected $longitude;
    
    protected $city;
    
    protected $address;
    
    //Getters and Setters
}

选项

array(
    'type' => TextType::class,      //Form type
    'lat_type' => TextType::class,  //Latitude form type
    'lng_type' => TextType::class,  //Longitude form type
    'options' => [],                //Form options
    'lat_options' => [],            //Latitude field options
    'lng_options' => [],            //Longitude field options
    'city_options' => [],           //City field options
    'address_options' => [],        //Address field options
    'lat_name' => 'latitude',       //Latitude field name
    'lng_name' => 'longitude',      //Longitude field name
    'city_name' => 'city',          //City field name
    'address_name' => 'address',    //Address field name
    'map_width' => '100%',          //Map box width
    'map_height' => '400px',        //Map box height
    'default_lat' => '42.69',       //Default latitude start
    'default_lng' => '23.32',       //Default longitude start
    'city' => true,                 //City field status
    'address' => true,              //Address field status
    'jquery' => true,               //Enable/Disable jQuery
    'map_template' => 'styled',      //Enter template name (Options: false = default, 'night' = Night template, 'styled' = Styled map template)
    'map_type' => 'terrain',        //Set map type (Options: 'roadmap' and 'terrain')
    'input_placeholder' => 'Enter location', //Set placeholder to search location input
)

功能

  • 仅获取地图
  • 创建自定义地图模板
  • 集成其他谷歌地图API功能
  • 添加约束

作者

  • Alexander Dimitrov - 初始工作 - cyberJaw