📜 ⬆️ ⬇️

Symfony + Google Maps API + Phoogle

Perhaps someone will benefit from a plan to work with the Google Maps API in the symfony framework (and I write for myself, because I’m afraid to forget :). The example uses the Phoogle class.

So:
1) Place PhoogleMap.class.php in the lib folder, in the code set the received apiKey ($ apiKey).
At once I will make a reservation that the code inside the class had to be corrected a little.

First, write the obvious things - the values ​​for:
$ mapWidth
$ mapHeight
$ apiKey
$ zoomLevel
Plus, register id diva with a map, for example, inside showMap ().
')
Secondly, I had to tweak the function showMap () a little, line by line:

echo "\ n <div id = \" map \ "style = \" width: ". $ this-> mapWidth." px; height: ". $ this-> mapHeight." px \ "> \ n
\ n "; // clearly indicate that the width and height of divas are px

- inside the if (GBrowserIsCompatible ()) condition
add after var map = new GMap (document.getElementById (\ "map \"));
map.enableScrollWheelZoom (); // for the possibility of approaching-removing the twitch of the mouse
map.enableDoubleClickZoom (); // for the possibility of approaching with a double click

geocoder = new GClientGeocoder ();
geocoder.setBaseCountryCode ('ru'); \ n ";


- further in the cycle for ($ g = 0; $ g <$ numPoints; $ g ++)
add new GIcon (icon) inside var marker ". $ g." = new GMarker (point ". $ g.", new GIcon (icon)); \ n

- if it is necessary to handle the onmouseover event, then write:
GEvent.addListener (marker ". $ G.", \ "Mouseover \", function () {\ n ";
default onclick event: GEvent.addListener (marker ". $ g.", \ "click \", function () {\ n ";
Well, in that case, of course, you should handle the onmouseout event to close the infoWindow:

echo "GEvent.addListener (marker". $ g. ", \" mouseout \ ",
function () {
marker ". $ g.". closeInfoWindow ();
}); \ n ";


And if you need to handle any event when onmouseover on any element on the page that is not related to the map (for example, I need to hover over the list item appeared on the map infoWindow, as well as highlighting the text in the list), we write something like this:
echo "GEvent.addDomListener (document.getElementById ('listTaxi'). getElementsByTagName ('p') [". $ g. "], 'mouseover', function () {
this.style.color = '# E5A8A8';
this.className = 'over' \ n ";
echo "marker". $ g. ". openInfoWindowHtml (\" ". $ this-> validPoints [$ g] ['htmlMessage']." \ ");
}); \ n ";

Similarly for the onmouseout event:

echo "GEvent.addDomListener (document.getElementById ('listTaxi'). getElementsByTagName ('p') [". $ g. "], 'mouseout', function () {
this.style.color = 'black'; \ n ";
echo "marker". $ g. ". closeInfoWindow ();

}); \ n ";


2) IndexSuccess template fish looks like this:
<? php $ map-> printGoogleJS ()?>

<? php $ map-> addGeoPoint ($ resultset-> getString ('latitude'), $ resultset-> getString ('longitude'), $ o); ?>

<? php $ map-> showMap (); ?>


3) In the action module of actions.class.php register:

class indexActions extends sfActions
{
public function executeIndex ()
{
$ this-> map = new PhoogleMap ();
$ this-> map-> centerMap (55.7557, 37.6183); // center along the Manege Square
}
}

Source: https://habr.com/ru/post/36987/


All Articles