gowsram/g-maps

ZF2 Google Maps 模块

dev-master 2015-01-08 11:56 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:30:22 UTC


README

Total Downloads zf2-google-maps-

Google maps - ZF2 模块

一个用于通过 gmaps api 生成 Google 地图的 zend framework 2 模块。

安装

主要设置

通过克隆项目

  1. 此模块可在 Packagist 上找到。在你的项目的 composer.json 中使用

    {   
        "require": {
    		"php": ">=5.3.3",
    		"zendframework/zendframework": "*",
    		"gowsram/g-maps": "dev-master"
    }
  2. 或者将此项目克隆到你的 ./vendor/ 目录。

使用方法

  1. 编辑你的 application.config.php 文件,确保 modules 数组包含 GMaps

    <?php
    return array(
    	
    		'modules' => array(
        		'Application',
        		//...
        		'GMaps',
    		),
    		//...
    );
  2. 在以下任一处添加 Google Maps API 密钥:

    • 你的模块的 config/module.config.php
    • 应用 config/autoload/global.php
    • 应用 config/autoload/local.php (建议这样做以避免发布你的 API 密钥)
    <?php
    return array(
    	'GMaps'=> array(
    		'api_key' => 'Your Google Maps API Key',
    	),
    	//...
    );
  3. 在控制器中

    $markers = array(
            'Mozzat Web Team' => '17.516684,79.961589',
            'Home Town' => '16.916684,80.683594'
        );  //markers location with latitude and longitude
    
        $config = array(
            'sensor' => 'true',         //true or false
            'div_id' => 'map',          //div id of the google map
            'div_class' => 'grid_6',    //div class of the google map
            'zoom' => 5,                //zoom level
            'width' => "600px",         //width of the div
            'height' => "300px",        //height of the div
            'lat' => 16.916684,         //lattitude
            'lon' => 80.683594,         //longitude 
            'animation' => 'none',      //animation of the marker
            'markers' => $markers       //loading the array of markers
        );
    
        $map = $this->getServiceLocator()->get('GMaps\Service\GoogleMap'); //getting the google map object using service manager
        $map->initialize($config);                                         //loading the config   
        $html = $map->generate();                                          //genrating the html map content  
        return new ViewModel(array('map_html' => $html));                  //passing it to the view
  4. 在视图中

    <?php echo $this->map_html; ?>