EGMap Google Maps Extension Examples v.1.8

I am about to update the information about EGMap for the newest version. Backwards compatibility has been broken, information and examples of previous version 1.8 will be held in this post, though it wont be supported anymore. This post will be eventually deleted.


Inspired on the symphony plugin [Symphony plugin developed by Fabrice Bernhard]( "sfEasyGMailPlugin") EGMaps provides a very easy way to implement Google Maps on your Yii application.

There have been major changes in version v.1.8. With the inclusion of utility libraries (plugins) the extension jumps onto a new level. Still, even though the extension is its early stage, I believe you can all take advantage of the easiness of its use to seamlessly include Google maps on your Yii site.


24-01-2011 version 1.8

  • Added MapType Controls Styles and Positioning

  • Fixed minor bugs throughout all the library classes

  • Included EGMapPoint and EGMapSize classes to the library

  • Code cleaning, improved code algorithms

  • Included EGMapKeyDragZoom class to allow ‘shift-click-and-drag’ option

  • Included EGMapControlPosition Class, now we can easily set controls on different positions on the map

  • Included EGMapMarkerWithLabel class to allow markers with labels

  • Included EGMapMarkerClusterer class to support marker clusterer feature

  • Fixed common sharing info window option. Now users can choose whether to share a common info window variable or not

  • Improved options encode. Included modified version of CJavaScript::encode to properly render Google Maps options.

10-01-2011 version 1.7

  • Fixed EGMapMarkerImage rendering bug

  • Added Support for Global Info Window Reference. Now, only one info window is open at all times. (Thanks bitmatix)

10-01-2011 version 1.6

  • Removed EGMapIcon class (deprecated for Google Maps v3)

  • Modified

  • Added setIcon, getIcon, setShadow, getShadow functions to EGMapMarker class

  • Removed deprecated functions and references on EGMap class

06-01-2011 version 1.5

  • Removed global_variables dependency

  • Fixed minor javascript bug for global variables

  • Fixed minor naming rendering bugs (jsName)

  • Included possibility to change jsName

24-12-2010 version 1.4

  • Fixed marker reference when rendering multiple maps

  • Fixed directions reference when rendering multiple maps

  • Fixed global variables registration bug

  • Fixed minor rendered javascript bugs

  • Fixed rendering container bug THANKS MDOMBA (Yii support really rocks!)

  • Added appendTo function to add maps to a container ID in the page

  • If no appendTo JQuery ID is set, Maps will be appended to document

  • Removed initialization function name dependency. Now the function is related to Map Ids.


  • Fixed bug on getMarkersFittingZoom function

  • Fixed bug on getMarkersCenterCoord function


Google API Key if you are going to use static maps. The library comes with a default key for ‘localhost’. Check at its source code to find out about its setAPIKey() method.

Developed with latest stable version of Yii (1.1.6)


Unzip its contents and place the gmaps folder into your protected/extensions folder.


This examples where written all in a view file.

Example #1

Simple map with an icon


$gMap = new EGMap();


$gMap->addMarker(new EGMapMarker(51.245475,6.821373));

$gMap->addMarker(new EGMapMarker(46.262248,6.115969));



Example #2

Simple Map with an infoWindow


 $gMap = new EGMap();


 $gMap->setCenter(39.721089311812094, 2.91165944519042);

 // Create GMapInfoWindow

 $info_window = new EGMapInfoWindow('<div>I was living here as a kid!</div>');

 // Create marker

 $marker = new EGMapMarker(39.721089311812094, 2.91165944519042, array('title' => '"My Town"'));




Example #3

Two maps on the same page (you can put as many as you wish)


This is an updated version example for version gmap v.1.2. Previous, downloads please update versions!



 $gMap = new EGMap();

 // No need to set it up anymore, EGMap handles it automatically

 // Do this if you want more IDs control

 // $gMap->setContainerId('map1');


 $gMap->setCenter(39.721089311812094, 2.91165944519042);

 // Create GMapInfoWindow

 $info_window = new EGMapInfoWindow('<div>I was living here as a kid!</div>');

 // Create marker

 $marker = new EGMapMarker(39.721089311812094, 2.91165944519042, array('title' => '"My Town"'));



 // we can now render to any containers in the document, we control where

 // we want it to be rendered now without coding the HTML elements for the

 // Google map

 // If we do not specify the container, the map will be rendered to the BODY 

 // tag of the document



 $gMap = new EGMap();

 // Not needed but you can do it for more control

 // over IDs

 // $gMap->setContainerId('map2');

 // changing proportions




 $sample_address = 'Calle de la Campana, 07800 Inca, Spain';


 // Create geocoded address

 $geocoded_address = new EGMapGeocodedAddress($sample_address);



 // Center the map on geocoded address

 $gMap->setCenter($geocoded_address->getLat(), $geocoded_address->getLng());


 // Add marker on geocoded address


      new EGMapMarker($geocoded_address->getLat(), $geocoded_address->getLng())






<div id="map2_container" style="width:512px; height:400px;float:left;padding:5px"></div>

Example #4

Include a custom icon marker, a labelled Marker (since version 1.8), and position map type controls with style drop-down.

Style class required for the example. Include it in your test view.


<style type="text/css">

.labels {

 color: red;

 background-color: white;

 font-family: &quot;Lucida Grande&quot;, &quot;Arial&quot;, sans-serif;

 font-size: 10px;

 font-weight: bold;

 text-align: center;

 width: 40px;     

 border: 2px solid black;

 white-space: nowrap;




Now the PHP code


$gMap = new EGMap();


// let's change position and style of the map type controls

$mapTypeControlOptions = array(

	'position'=> EGMapControlPosition::LEFT_BOTTOM,




// set center

$gMap->setCenter(39.721089311812094, 2.91165944519042);

// Create GMapInfoWindows

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

$info_window_b = new EGMapInfoWindow('Hey! I am a marker with label. Drag me!');


// Create custom icon	

$icon = new EGMapMarkerImage("");

$icon->setSize(32, 37);

$icon->setAnchor(16, 16.5);

$icon->setOrigin(0, 0);


// Create marker

$marker = new EGMapMarker(39.721089311812094, 2.91165944519042, array('title' => 'Marker With Custom Image','icon'=>$icon));

// Set its infoWindow (INFO_WINDOW is shared -please check 

// addHtmlInfoWindow params for more info)




// Now Create marker with label

$marker = new EGMapMarkerWithLabel(39.821089311812094, 2.90165944519042, array('title' => 'Marker With Label'));

// Options for the style of the label

// Please see plugin reference for more details

// (included link on source code)

$options = array(





// Setting marker label options

$marker_options = array(





  'labelAnchor'=>new EGMapPoint(22,0),




// We can also set its options this way

//$marker->setOption('labelContent', '$425K');

// Once set, options are CJavaScript::encoded internally





//$marker->setLabelAnchor(new EGMapPoint(22,0));

// attach second info window	

$marker->addHtmlInfoWindow($info_window_<img src='' class='bbc_emoticon' alt='B)' />;




Fantastic extension! Have you made any additional progress?

Do you have any examples for 1: Circles and 2: Polygons?

Yes there are, check , no much time to update anything

Have you considered the possibility of choosing different map layers than those offered by Google? For example, the Open Street Map layers. It might be that in order to do that, you will need to support both the Google Maps backend as well as the OpenLayers backend. Though, I fear adding support for another backend to this extension would probably require quite a decent work.

If I was to do something different, I would probably go for

Nevertheless, no time at all at the moment…

I am a newbie in yii,I want to use this EGmaps extension in my application, but is there any tutorial on how to config the extension?

Thanks for your help. the version I want to try is EGmaps v2.0


Thanks for this extentions.

Tell me please, how make "reposition" marker with this extention.

Sorry for my english.

Hi Antonio,

Firstly, thanks very much for this extention.

And i am using this for one of my project with need to display all the addresses in one map.

The problem that i am having is the info windows which cannot display properly i the close button (x) is disappear.

Could you please take a look at my attach image and please tell he how to solve this problem?

Thank you very much



I’m having the same problem - did you find a solution?


Hi Matt,

Got the same problem as you. Found the fix, just add the following style to the page that render the map:


#EGMapContainer0 img{max-width:none}


EGMapContainer0 is the default id, change this to whatever you map canvas id is.

Hi all,

I’m using this extension in my website, but left-side controls are shown this way:

Any ideas?


It was bootstrap.css (img {max-width:100%;}) playing with my patience!

I’m also having problems with the reposition graphic marker appearing, see:


I’ve tried adding this … but it does not fix it.

// egMap icon fix

#EGMapContainer0 img{max-width:none}

Any suggestion?


I am using egmap for long time now for my projects.

Recently I bumped into this problem:

Can somebody reproduce the problem with Firefox 23?

Best Regards



Thanks for the great extension! I’m having a minor problem setting the width of my info windows.

$infoBox = new EGMapInfoBox('<div class="map-icon">' . $infoBoxContent . '</div>');

$infoBox->maxWidth = 100;

$image = new EGMapMarkerImage('/images/mapitem/' . $icon->icon_id . '.png');

$image->setSize(21, 18);

$marker = new EGMapMarker($icon->map_lat, $icon->map_lng, array('title' => $icon->node->title, 'icon' => $image, 'visible' => false), 'mapicon' . $icon->id);



This has no effect and the width is always determined by the content. Any ideas?

Many thanks

buenas tardes!!! estoy queriendo exportar el mapa a pdf alguien sabe como puedo hacerlo? desde ya muchas gracias

I want to make the infoWindow appear when hover/mouseover to multi-polygon(different infoWindow in different polygon) and data in infoWindow retrieve from database. I’ve try to implement by this code in view:

$info = new EGMapEvent('mouseover', "function (event) { $.ajax({



                                            'data'<img src='' class='bbc_emoticon' alt=':(' />{'lat':, 'lng': event.latLng.lng()}),


                                        });}", false, EGMapEvent::TYPE_EVENT_DEFAULT);






And this code in TabelpolyController:

public function actionView($id)






Until this far, nothing’s appear when hover to the polygon. Anyone can help me please? Or is there another way to do this? Thank you

Hi Antonio Ramirez,

Great job, congrat!

It’s possible auto center/zoom to display all markers?