Yii 1.1: gmap

Simple google map implementation

This extension allows you to use google maps on your page. You just put address and widget does the rest. It also has an extensive client side, so you can later interact with the map using fairly simple API.




  • Yii 1.0 or above


  • Extract the release file under protected/extensions


See the following code example:

$this->widget('application.extensions.gmap.GMap', array(
    'id' => 'gmap',//id of the <div> container created
    'key' => '...', //goole API key, should be obtained for each site,it's free
    'label' => 'some company', //text written in the text bubble
    'address' => array(
        'address' => '1600 Amphitheatre Pky',//address of the place
        'city' => 'Mountain View', //city
        'state' => 'CA'//state
        //'country' => 'USA' - country
        //'zip' => 'XXXXX' - zip or postal code

This generates nearly the following

<div id="gmap"></div>
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=..." type="text/javascript"></script>
<script src="/assets/f71433f3/gmap.js" type="text/javascript"></script>
<script language="javascript">
var GMAP_DEF_LAT = 54.863963;
var GMAP_DEF_LNG = 1.73584;
var GMAP_DEF_ZOOM = 7;
var m = new GMap("gmap", "1600+Amphitheatre+Pky,+Mountain+View,+CA", "some company");

As you see, there is an object - m, it can be used in any JS scripts. It has the following methods:

  • Constructor - accepts ID of the div container, address and label. Constructs an object, doesn't affect any markup.
  • setAddress - accepts string with address in the form of ADDRESS, CITY[, STATE][,COUNTRY][,ZIP]. Alternative way - specify an object {address:'',city:'',state:'',country:'',zip:''}. Address AND City AND (State OR Country) are required.
  • setLabel - sets the label. If label is empty, address will be show in the text bubble.
  • show - renders the map, sets the marker.

If you use widget without specifying an address, you will get the same, but will have to m.setAddress and call m.show() manually. This may be used for showing user his place when hitting Refresh button.

Change Log

January 18, 2009

  • Initial release.

Total 4 comments

#12297 report it
rajesh chaurasia at 2013/03/12 12:29am

this extension is working fine.its very very helpful.

#11080 report it
sirin k at 2012/12/14 03:32pm
is there is any way to plot the gmap inside a fancy box?

is there is any way to plot the gmap inside a fancy box? i tried but failed.


#9499 report it
matteosistisette at 2012/08/17 03:40pm
Doesn't work with null or empty address

If you set an address that can't be found, such as "XXXXX", a map without a marker centered at the default latitude and longitude is shown, as expected.

However, if you don't set the address at all or set it to '', then no map is shown at all. I would expect it to show up at the default lat and lng exactly the same as when the address can't be found.

The hackaround if you want to show the default map is to explicitly set a dummy address like "XXXXXXXXXX".

#6325 report it
bonnie at 2011/12/29 08:32pm
Add label for directions and more

How can I get to put a link with label Directions so that people when click on it they will pass in the address and get to full Google map to get directions. Also any way to pass in more labels I would like to pass in the star ratings too. Am using it for business rating. Thanks. Please.

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: KJedi
  • Category: Others
  • Votes: +4
  • Downloaded: 3,056 times
  • Created on: Jan 18, 2009
  • Last updated: Jan 18, 2009