CakePHP用にGoogleMapヘルパーを作った
JQueryの勉強でGoogleMapの呼び出しをJQueryのプラグインにして、それを簡単に呼び出せるHelperをCakePHPの形式で作成したのでgitHubに公開してみる。
git@github.com:hidetoshing/googlemaps.git
基本の使い方は
<?php echo $this->Html->script('http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js', array('inline' => false));?> <?php echo $this->Html->script('http://maps.google.com/maps/api/js?sensor=false', array('inline' => false));?> <?php echo $this->Html->script('/googlemaps/js/jquery.googlemap.js', array('inline' => false));?> <h1>googlemap sample: map with daraggable marker with geocoding.</h1> <div id="contents"> <?php echo $this->Googlemap->map( array( 'height' => '600px', 'width' => '600px', 'latitude' => "30", 'longitude' => "140")); $this->Googlemap->addDraggableMarker(array( 'lat_field' => '#testLat', 'lng_field' => '#testLng', 'latitude' => "30", 'longitude' => "140", 'icon' => 'http://maps.google.co.jp/mapfiles/ms/icons/blue-pushpin.png')); $this->Googlemap->geocoding(array( 'address_field' => '#testAddress', 'submit_button' => '#geopick_button')); echo $this->Googlemap->toScript(array('inline' => false)); ?> </div> <?php echo $this->Form->input('address', array('id' => 'testAddress'));?> <?php echo $this->Form->button(__('Find', true), array('type' => 'button', 'id' => 'geopick_button')); ?> <?php echo $this->Form->input('lat', array('id' => 'testLat')); ?> <?php echo $this->Form->input('lng', array('id' => 'testLng')); ?> <!-- / #contents --></div>
こんな感じで、入力された住所に連動してドラッグ可能なマーカが付いたGoogleMapが表示出来る。
マップオプションは今のところ、latitude, longitude, zoomに対応、マーカはdraggable, iconの変更のカスタマイズが出来る。