如何在Yii中使用MySQL DB进行EGmap扩展

时间:2012-05-18 02:48:35

标签: mysql google-maps yii

例如我有一个包含纬度和经度的MySQL数据库,如何调用这些坐标在地图中显示?有人可以帮我吗?

1 个答案:

答案 0 :(得分:2)

由于您的问题和信息有点不清楚,这些是我的假设:

  1. 我假设你已正确遵循指令安装EGMap 扩展到您的yii应用程序。
  2. 您想在所述坐标处放置一个标记(纬度& 经度)。
  3. 示例代码:(请调整以适合数据库表格和行的列 评论为“//从表格位置获取LatLong”)。将此直接放入您的视图文件示例:protected / views / site / index.php

    <!-- other html codes here -->
    <div id="map-container">
    <?php
    // Get LatLong from table Location
    $location=Location::model()->findByPk(1);
    $latitude = $location->latitude;
    $longitude = $location->longitude;
    
    Yii::import('ext.gmap.*');
    
    $gMap = new EGMap();
    $gMap->setJsName('map');
    $gMap->zoom = 10;
    $mapTypeControlOptions = array(
        'sensor'=>true,
        'position'=> EGMapControlPosition::LEFT_BOTTOM,
        'style'=>EGMap::MAPTYPECONTROL_STYLE_DROPDOWN_MENU
    );
    // Map settings
    $gMap->mapTypeControlOptions= $mapTypeControlOptions;
    $gMap->setWidth(800);
    $gMap->setHeight(600);
    $gMap->setCenter($latitude, $longitude);
    
    // Prepare icon
    $icon = new EGMapMarkerImage("http://google-maps-icons.googlecode.com/files/gazstation.png");
    $icon->setSize(32, 37);
    $icon->setAnchor(16, 16.5);
    $icon->setOrigin(0, 0);
    // Prepare marker
    $marker = new EGMapMarker($latitude, $longitude, array('title' => 'Gas Station','icon'=>$icon));
    $gMap->addMarker($marker);
    
    $gMap->renderMap();
    ?>
    </div>
    <!-- other html codes here -->
    
相关问题