Incodius™ News


What's happening in our world of creative web development.



e:info@incodius.co.nz

..........................................................................................
WE TWEET:  incodius Google fonts have added lots of new fonts! http://www.google.com/webfonts


« Back

Super simple Google Maps Smarty Plugin - download the file



We've talked about Smarty before, here, and wrote about how we love templating as a smooth way to separate the Vs from your Ms and Cs in an MVC-structured site.

 

Recently I needed to create Google Maps for Out Takes Film Festival. In the past we've either embedded these directly into the templates for contact pages, or allowed the client to paste in the embed code for locations. Both of these have their drawbacks and I wanted to create dynamic Google maps without requiring the client, who was uploading all the content on a tight schedule, to copy and paste from Google Maps.

 

 

alt

Out Takes Film Festival google maps plugin
Photo:Outtakes dot org

 

 

There are other plugins for creating maps but they all require the co-ordinates of the location, whereas I wanted to pass the location to Smarty as a human-readable text address that I was dynamically creating for each location based on database content, and have the plugin do ALL the work.

 

The result is a concise plugin that takes in 3 parameters: the full address of the location, and the height and width of the map you want displayed. It then uses the Google Maps API to geocode that address, and extracts the latitude and longitude from the resulting XML. Then, the plugin returns a string of the embed code to the template, giving you the standard iFrame embedded Google Map of your location, in the desired height and width, with location bubble as well. And as it's basically just a PHP function, you should be able to put this to good use even without Smarty just by changing the way it's called depending on where you're using it.

 

 

Sound handy? The file is below. To create a map, in your smarty template you simply write:

{googlemapaddress fulladdress=$fulladdress mapwidth="400" mapheight="350"}

where $fulladdress is a text address (e.g, My House, 34 Something St, Anywhereville) that has been assigned in PHP, and the height and width are whatever you choose to fit within your layout.

 

Click here to download the zipped plugin file, which you will need to put into your smarty/libs/plugins directory.

 

Happy coding!

 

- Rita Langley

 


« Back