Invalid Article.

Google static maps helper for CakePHP

By Karl Mendes (kmendes)
This is a simple CakePHP helper to create static maps using google API. For more information on the api and how to get an api key consult the Google Static Maps API.

1. Add helper file to your app

Download the file google_static_map.php (http://karlmendes.com/static/google_static_map/google_static_map.zip) and add it to the folder “YOUR_APP/views/helper”.

2. Add your google api key to the core.php

Add the following line to core.php to define the google api key:

Download code <?php
Configure
::write('GoogleMapsAPIKey''---KEY---'); 
?>

3. Reference it on your controller

Refer the helper on the controller together with the other helpers you may be using.

Download code <?php 
var $helpers = array('Html','Form','Javascript','GoogleStaticMap');
?>

4. Use it in your view

To use ti just call the function map using the desired parameters, this is a simple example:

Download code <?php
$params 
= array(
    
'markers'=>array(array(-4,40),array(-20,80)),
    
'size'=>array(400,300),
    
'zoom'=>12
    
);
echo 
$googleStaticMap->map($params);
?>

For those willing to take a quick look at the helper code go to the next page, if you got what you want already stop right here.

Page 2: The code behind

Comments 1416

CakePHP Team Comments Author Comments
 

Comment

1 hi

Hai, Karl , you have shared really an important information for me. The CakePHP helper to create static maps using google API is very user friendly and useful for me. I gone through every step as per your instructions. I really got what I wanted. I was searching for the same thing from so many days. Your site is really giving a great knowledge and nice stuff for the people like me . I was confused earlier about the implementation of the helper. You solved my problem. More such information will be welcomed from time to time. Call Center Software
Posted Apr 20, 2010 by brown