[extension] Google maps

http://www.yiiframew…extension/gmap/

Any feedback is appreciated.

UPDATE:

Please upgrade to the next version, there is a little bug, that comes out when location is not found.

Cool!

will try it out soon (just found Yii today).

Is there a way to add several locations on a map, or just one?

Ok, worked straight out of the box! Nice, thanks…

I made some improvements to /gmap/GMap.php (line 113):



<div id="'.$this->id.'"></div>


At first I changed that so users with javascript turned off would see a message:



      <script type="text/javascript" charset="utf-8">


      //<![CDATA[


      document.write('<div id="'.$this->id.'"></div>');


      //]]>        


      </script>


      <noscript><b>Javascript must be enabled in order to use Google Maps.</b></noscript>


After that I thought: why can’t we set the size of the map as well?

So, I made some more changes:

  1. GMap.php (line 113):


      <script type="text/javascript" charset="utf-8">


      //<![CDATA[


      document.write('<div id="'.$this->id.'" style="width:'.$this->width.';height:'.$this->height.'"></div>');


      //]]>        


      </script>


      <noscript><b>Javascript must be enabled in order to use Google Maps.</b></noscript>


  1. GMap.php (line 9, below public $id;)

add:

	public $height;


	public $width;
  1. code example:


<?php


$this->widget('application.extensions.gmap.GMap', array(


    'id' => 'gmap', //id of the <div> container created


    'height' => '400px', // height of the gmap


    'width' => '700px', // width of the gmap


    'key' => '...', //goole API key, should be obtained for each site,it's free


    'label' => 'some company', //text written in the text bubble


    'address' => array(


        ....


        )


));


?>


Sry for changing even more stuff :)

I re-cleaned the public function run() in gmap.php:

<?php 


// somewhere near line 111, change the whole public function run()


// ...





	public function run()


	{


		echo '


      <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key='.$this->key.'" type="text/javascript"></script>


      <script src="'.CHtml::asset(dirname(__FILE__).DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'gmap.js').'" type="text/javascript"></script>


      <script type="text/javascript" charset="utf-8">


      //<![CDATA[


      document.write('<div id="'.$this->id.'" style="width:'.$this->width.';height:'.$this->height.'"></div>');


      //]]>        


      '.$this->js.'


      </script>


      <noscript><b>Javascript must be enabled in order to use Google Maps.</b></noscript>        


    ';


	}


Nice, thanks! :)

Will make these changes when I have time.

Also, after publishing this extension, I modified it according to customer’s needs and now it shows one point initially and then it can show direction from second point to initial one. I’ll refactor my code and publish the ready extension cause current code is messy :)

Very nice extension, but it seems to me, that setting the zoom doesn't work!

any solution?

You set default zoom, not zoom when object is found. By default, when address is notfound it centers on UK and zoom shows all UK.

Zoom for the spot is 13, it is hardcoded in gmap.js class

Nice extension Konstantin… works like a charm out of the box.

Thanks for the updates beatniak.  They work great as well.

Cheers,

R

I've been developing a heavily modified version of this extension that will use Google Static Maps API in the event that the user has javascript disabled, and has more customizable attributes (you can pass an array of lat/lngs to have a variety of very customizable markers appear).

Is anybody interested enough in this that I should put it into an extension?

@sclark: I'm interested in that. It would be great if you put that in an extension.

Alright, sounds good. I’ll tidy it up and put it up when I get a chance  :)

The only downside is that to check if javascript is off, you'll need to come up with a clever hack (it would vary on the situation) to send a variable to the widget telling it if javascript is on or off.

Is it possible too add point from latitude and longitude?

i have some questions about this extension…

Are the functions you define in the gmap.js the ones that are in the google maps API? I ask this because i can’t find those functions anywhere… :mellow:

Where do you declare the variable m, in gmap.js?????? :unsure:

im asking these questions because i want to alter the extension so it supports the definition of points with lang and long instead of addresses

Hi,

Have you come up with advance version of this widget?

I know that this is a very old post but I need help…

Got an error on this line:

document.write(’<div id="’.$this->id.’" style=“width:’.$this->width.’;height:’.$this->height.’”></div>’);

it says "Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in… "

Any ideas?

Thanks.

I’ve modify the width and height directly in the css and added the <noscript> line. Everything works fine.

is there is any extension like this to show route map from an address to an address ??? Help me

Thanks for extension , I had tested

Thanks for the great work, I’m planning on using this in a project.