谷歌地图上的中心标记 - Yii egmap

时间:2014-05-13 17:28:00

标签: yii yii-extensions

我希望地图在显示多个标记时正确居中和缩放。

    //import
    Yii::import('ext.egmap.*');

    //basic setup
    $gMap = new EGMap();
    $gMap->setWidth(953);
    $gMap->setHeight(552);
    $gMap->zoom = 16;
    $gMap->setCenter(38.257818,-7.992712);

    //setup info windows:
    $info_window_a = new EGMapInfoWindow('<div>I am a marker with custom image!</div>');


    //setup marker icon
    $icon = new EGMapMarkerImage("/images/experiences/iconLocal.png");
    $icon->setSize(30, 30);
    $icon->setAnchor(16, 16.5);
    $icon->setOrigin(0, 0);

    //setup markers
    $markerA = new EGMapMarker(38.257818, -7.992712, array('title' => 'Marker A - With Custom Image','icon'=>$icon));
    $markerA->addHtmlInfoWindow($info_window_a);
    $gMap->addMarker($markerA);

    $markerB = new EGMapMarker(38.257818, -7.99333, array('title' => 'Marker B - With Custom Image','icon'=>$icon));
    $markerB->addHtmlInfoWindow($info_window_a);
    $gMap->addMarker($markerB);

    //place them together - but I see no use for them at this time.
    $markers = array($markerA, $markerB);

    //try to map center those markers:
    $gMap->centerOnMarkers();

    //render
    $gMap->renderMap();

结果:我没有集中元素。

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您应该使用centerAndZoomOnMarkers()功能。

第一个参数$margin允许您定义最小边界周围的缩放因子。

$gMap->centerAndZoomOnMarkers(0.5);