Jan 12
Digg
Stumbleupon
Technorati
Delicious

Phoogle usage with Symfony

If you have ever needed a way to include Google Maps functionality into your project you should know what is Phoogle. There is also GoogleMap plugin for Symfony but I was not able to make it adding a point to a map based on lang an long values.
So it’s good to know that there is Phoogle php class which is going it simplify the life for developer:

http://www.systemsevendesigns.com/phoogle

Here is what they wrote about theirselves:

Phoogle Maps (pronounced like Foogle Maps) is a PHP class that integrates itself with the Google Maps API and with the Google Geocoding API to make an easy to use interface to display Google Maps on your site. With about 5 lines of PHP code you can display a customized Google Map on your website. Please note that you will need a free Google Maps API Key to use Phoogle Maps

And that’s the truth. If you need to have a quick way to display a point on world map – IMHO the easiest way is to use Phoogle.

Anyway, now.. does not matter if you’ll use pure Google Map API or Phoogle wrapper.. in both cases you may get into a small trouble with integrating it into symfony: how to add google map javascript code into header of only specific pages of your project.

Here is a trick for this (I found it on symfony forum, btw):

So you have to have this code in your layout.php template:

&lt?php if (has_slot(‘gmapheader’)): ?>
&lt?php include_slot(‘gmapheader’) ?>
&lt?php endif; ?>

Now dont forget to put phoogle class files into your lib/ folder.
And next step – for the pages where you want to show Google Map insert the following code into templates:

$map = new PhoogleMap();
$map->setAPIKey(YOUR_GOOGLEMAP_KEY_HERE);
$map->setWidth(700);
$map->setHeight(400);
$map->addGeoPoint($lat, $lon, ‘It is here!’);

slot(‘gmapheader’);
$map->printGoogleJS();
end_slot();

echo $map->showMap();

This little trick works not only for Phoogle of course. You may use slot functionality as your additional weapon for inclusion of different javascript blocks or design elements.


Author: symfonian

6 Comments

[…] Phoogle usage with Symfony […]

[…] Phoogle usage with Symfony […]

Williams
June 30, 2008

Hello, very good this text but you have examples?

[…] Phoogle usage with Symfony […]

[…] is available about using symfony with geo services. Some time ago we’ve already written about usage of phoogle (php lib for google map) with symfony but it’s not supported since […]

Comments RSS TrackBack Identifier URI

Leave a comment