sfEasyGmapPlugin is a very easy to use Google Maps API plugin for symfony, inspired by the Phoogle class... but better
A very simple version has been available for a few months but I have now finally released the 1.0 version, with the following new features :
- it is now sf1.2 compatible straight out of the box
- it has some unit tests
- the GMap constructor now takes an array of parameters, which is much more flexible and also more in the symfony coding spirit (Warning : the modification of the GMap constructor should break your application if you used the prior version of sfEasyGMapPlugin)
- there are interesting functions concerning Bounds :
- smallest enclosing bound
- propel criteria "in bounds"
- homothety transformation
- zoomOut transformation
- there are interesting functions concerning conversion from/to lat/lng to/from Google's pixel coordinates system. These can be very useful if you want to guess the bounds knowing only the center lat/lng, the zoom level and the map's width/height in pixels. They involve a few mathematical formulas that were not so straightforward, (since you need to understand how Google's projection works) so trust me, these functions are valuable, even if they only concern power users.
I have also developed a few doctrine-specific functions which are unfortunately not available yet because not generic enough. I will try to release them in the next version.
The official symfony page is here : http://www.symfony-project.org/plugins/sfEasyGMapPlugin
Please feel free to comment on this work in progress !
Mots-clefs : Google Maps, sfEasyGMapPlugin, symfony
Hi, congrats for work.
I tried symfony installation with:
$ symfony plugin:install sfEasyGMapPlugin
but I get:
<>
now I will try with svn checkout!
.. error message is broken:
–No release available for plugin “sfEasyGMapPlugin”–
The maps on Allomatch.com are now awesome (the list and the map are really connected in a user-friendly way). Is this related?
xdade : I found the reason of the pear error, I will correct that on monday. I unfortunately put 1.2.0 as maximum symfony version…
Laurent: the functions provided in the plugin and used on allomach.com indeed solve a typical problem of usability with Google Maps. For example you want to show the data around a certain place at a certain zoom level. How do you know the bounds of the zone visible on your map ? The first solution is of course to do it in two steps.
1. center and zoom the map on the place
2. do an ajax request to get the data in the bounds
But if you don’t want to do the ajax request, you will have to calculate the bounds using the projection system of Google Maps. This can be done using the plugin. For example with a 300×300 map :
$lat = 48.856536;
$lng = 2.339307;
$zoom = 11;
$pix = GMapCoord::fromLatToPix($lat, $zoom);
$ne_lat = GMapCoord::fromPixToLat($pix - 150, $zoom);
$sw_lat = GMapCoord::fromPixToLat($pix + 150, $zoom);
$pix = GMapCoord::fromLngToPix($lng, $zoom);
$sw_lng = GMapCoord::fromPixToLng($pix - 150, $zoom);
$ne_lng = GMapCoord::fromPixToLng($pix + 150, $zoom);
$bounds = new GMapBounds(new GMapCoord($sw_lat, $sw_lng), new GMapCoord($ne_lat, $ne_lng));
xdade: ./symfony plugin:install sfEasyGMapPlugin should now work again with any 1.2.x version of symfony
And here is a tutorial for Google Maps made in paper
(just for fun)
Pretty sure you’ll like it.
http://www.youtube.com/watch?v=I9TtDecveCE
merci Fabrice: i’m already trying the plugin with svn checkout, but other sfUsers will benefit
Hi,
I’ve tried your plugin, and it works great. Except, when I have output escaping turned on, which is really necessary for my site, the plugin fails because the generated code is.. well, escaped…
Is there a way to fix this, or work around it?
@andre : I never tested the plugin with output escaping on. I am a bit surprised it changes something. I do not see which variable goes through output escaping. The whole $gMap object ?
In that case, adding this line at the beginning of your template :
$gMap = $sf_data->getRaw(’gMap’);
might be the solution for you.
Thank you so much for your reply!
Unfortunately, your suggestion didn’t help. What I’m doing is using the helpers do write the container and the javascript, like:
'512px','height'=>'400px')); ?>In the generated code I then the code for the conatiner escaped, like:
<div id="map" style="width:512px;height:400px;"></div>Also, I get the following javascript error, also because the scripts are escaped:
Error: syntax error
Source File: …
Line: 318, Column: 14
Source Code:
google.load("maps", "2.x");I have tried different approaches to solve this, like loading the helpers in the component, generating the necessary code blocks as variables, and then using getRaw() in the template, but no success.
Not sure why this happends, when i use the built in helpers like link_to() this works of course.
Aww, sorry!! My apologies, your code worked! It was just some issues with the quotations when I copied the code from the blog. :]
Thanks alot, please delete my previous posts, they hold no value..
@andre : don’t worry, the information that
$gMap = $sf_data->getRaw(’gMap’);is the solution when you use output escaping is interesting !
By the way, Google Maps was not working yesterday with the version 2.x. I had to patch the GMap.class.php to
google.load("maps", "2");I do not know if the Google bug was temporary, but maybe it is safer from now on to not use the version 2.x anymore… Even if it is still the recommended way to do. Yesterday, even the examples on maps.google.com were not working !
Hello, I’m already using your plugin. Thank you very much for the job.
Hi, I just found your symfony plugin. I want to map out IP addresses on a google map, and I couldn’t find any information about whether your API takes IP addresses. I saw examples of canonical addresses and long/lat. Can you tell me if it can take IP addresses and display the location?
Thanks and great work!
ipaddy: The plugin does not map ip addresses directly. For that you would need a specific database or web service.
However for your information, a good way to get this is to use Google Loader’s client information contained in the javascript object google.loader.ClientLocation
More information here :
http://code.google.com/apis/ajax/documentation/#ClientLocation
My experience is that it’s one of the most precise ip-based geolocation service, and it’s free. Only drawback is that it’s done client-side, so if you want to store it in database, you need to send an ajax request after the page is loaded.
Hi and congratulations for the plugin.
I’ve seen that the plugin can easily manage markers to show them, but is there some functionallity to put markers from user actions like map click?.
Thank you.
Thanks for the support !
Concerning adding markers with map click, we concentrated our efforts on the server-side part in the plugin.
Making good helpers for client-side interaction needs more thinking, because on the client-side, demands are usually much more specific. But we will try to include some basic client-side functionalities in the next version, like adding a marker with a click
Hi, I’ve got a problem when I install the plugin.
When I use it in my action.class.php (in apps/frontend/..) I got the following error :
Fatal error : Class ‘GMap’ not found in /my/project/path/
I did write this in my settings.yml :
all:
.settings:
enabled_modules: [default, sfEasyGMapPlugin]
Need Help
Have you tried
./symfony ccor
php symfony cc?
If the class is not found, it’s only because the class-autoloading is not initialized by symfony.
PS: a shorter answer, by Thomas Rabaix

Yes I already tried !
How to initialized the class-autolaoding ?
Symfony cc should work.
If it does not, it might be a permission problem. So :
- first erase the cache with
rm -rf cache/*- then visit any page of your project to regenerate the cache.
- check that you have
'GMapEvent' => '[project_path]/plugins/sfEasyGMapPlugin/lib/GMapEvent.class.php’,
‘GMapMarker’ => ‘[project_path]/plugins/sfEasyGMapPlugin/lib/GMapMarker.class.php’,
‘GMapIcon’ => ‘[project_path]/plugins/sfEasyGMapPlugin/lib/GMapIcon.class.php’,
‘GMap’ => ‘[project_path]/plugins/sfEasyGMapPlugin/lib/GMap.class.php’,
in your cache/[project]/[env]/config/config_autoload.yml.php
- If you have not, check that your class is in /plugins/sfEasyGMapPlugin/lib/GMap.class.php
- If not, then move them so that they are there
- Finish with sudo ./symfony fix-perms and ./symfony cc
I use ./symfony cc and fix-perms everytime I have a problem, it is the 1st thing a do.
I ereased the cache..
I don’t have this lines in config_autoload.yml.php
I Do have all the files in /plugins/sfEasyGMapPlugin/lib/
I tried ./symfony plugin:list
sfEasyGMapPlugin 1.0.3-stable #plugin.symfony-project.org (symfony-plugins)
I set the settings.yml file ..
setting the settings.yml is completely optional
However are you sure the path is [project]/plugins/sfEasyGMapPlugin/lib and not [project]/plugins/sfEasyGMapPlugin/trunk/lib for example ?
Omagad !!!
config/ProjectConfiguration.class.php all other plugin were forbidden ..
And now i get <div id=”map” style …
Is that because of app.yml ? or javascript ?
@ndre had the same problem : it’s output escaping. Just write :
$gMap = $sf_data->getRaw(’gMap’);
in your template to override it. And be careful to write it manually and not copy/paste it, or you will have the wrong quotes
Ok, good job
Thanks for your help and your work !
It is exaclty what I needed
PS: I miss the IP adresse detection too
Can I load only markers inside boundaries map?.
would it be possible to have a forum to share information and doubs about the plugin?.
thank you.
Doubts… which doubts ?
You can load markers wherever you want. Usually the best though in a complicated application is to load through Ajax only those in the visible boundary.
I think the forum is a good idea so I will try to open one soon !
Hey,
I’m trying to refresh my GMap after AJAX submit button, actually I update two :
- a list on the left
- map on the right
I’d like my map & markers to be refreshed by informations contained in the list.
The first div is updated and the GMap disappear ..
Great plugin! It’s saved me a lot of time.
Thanks for the $sf_data->getRaw() tip. I ran into another issue - if you put the map inside a partial, then it seems you have to do the getRaw twice, once in the template, and then inside the partial. I’m not sure why this is the case exactly, but it seems to work.
Have you considered including the google loader client IP geolocation as part of your plugin? I added this to GMap.class.php
public function getCenterLat()
{
if ($this->getCenterCoord()->getLatitude())
{
return $this->getCenterCoord()->getLatitude();
}
else
{
return ‘google.loader.ClientLocation.latitude’;
}
}
/**
*
* @return float
* @author fabriceb
* @since 2009-05-02
*/
public function getCenterLng()
{
if ($this->getCenterCoord()->getLongitude())
{
return $this->getCenterCoord()->getLongitude();
}
else
{
return ‘google.loader.ClientLocation.longitude’;
}
}
So if lat & long are set to null it tries to center based on IP geolocation.
I would definitely not include such a hack in the plugin ! This only works in javascript environment, when you use
<script>
< ?php echo $gMap->getCenterLat() ?>
</script>
In all other circumstances this will just break the code.
sfEasyGMapPlugin indeed generates javascript using PHP directly in the class, which is not a very clean practice. I actually think about using some templating architecture to improve the quality of the plugin and dissociate as much as possible javascript and PHP. In the meantime, javascript is generated only through functions which names end with “JS”, getMarkersJS, getMapJS etc. and no javascript should be included in any generic php functions, especially a simple getter
is there any functionality for drawing polylines and polygones
There are no fancy functionality concerning polylines and polygons. It is a pity since I made extensive use of them in the past, and I would have been happy to package this experience in the plugin. But right now my priority is to focus on the new v3 of the Google Maps API.
You are, however, welcome to contribute to the plugin by adding polylines and polygons classes
I really like this plugin!!
I would contribute adding the Google function to calculate the PATH between 2 addresses
Contact me if you want
Nicolas: it is always good to hear people ready to contribute. The best way is to send me a patch with your contribution and it will be included in the trunk if the quality (code and usefulness) is up to the standard set by the existing code.
Thanks a lot for this plugin. Works great.