Disponibles sur GoogleCode : http://code.google.com/p/phooglemap

PhoogleMap on Google Code

Sources de la version 2.1 de PhoogleMap :


<?php

/**
 * PhoogleMap | a PHP library for Google Map API.
 * Copyright (C) 2009 Alexandre JULIEN
 *
 * This library is under MIT License
 * Everybody can contribute, redistribute, modify this content.
 *
 * This library contains resources from the Phoogle PHP library which
 * is under GNU license.
 *
 * It's an enhancement of the original PhoogleMap which more functions.
 *
 * @classDescription PhoogleMap
 * @author Alexandre JULIEN
 * @tutorial <http://www.alexandre-julien.com>
 * @package PhoogleMap
 * @license GNU / GPL / MIT
 * @version 2.1 works on PHP 5.2.x and PHP 5.3
 * @copyright 2009 Alexandre JULIEN
 */
class PhoogleMap
{
 /**
 * validPoints : array
 * Holds addresses and HTML Messages for points that are valid (ie: have longitude and latitutde)
 */
 var $validPoints = array();
 /**
 * invalidPoints : array
 * Holds addresses and HTML Messages for points that are invalid (ie: don't have longitude and latitutde)
 */
 var $invalidPoints = array();
 /**
 * mapWidth
 * width of the Google Map, in pixels
 */
 var $mapWidth = 300;
 /**
 * mapHeight
 * height of the Google Map, in pixels
 */
 var $mapHeight = 300;

 /**
 * apiKey
 * Google API Key
 */
 var $apiKey = &quot;&quot;;

 /**
 * showControl
 * True/False whether to show map controls or not
 */
 var $showControl = true;

 /**
 * showType
 * True/False whether to show map type controls or not
 */
 var $showType = true;
 /**
 * controlType
 * string: can be 'small' or 'large'
 * display's either the large or the small controls on the map, small by default
 */

 var $controlType = array();

 /**
 * zoomLevel
 * int: 0-17
 * set's the initial zoom level of the map
 */

 var $zoomLevel = 5;

 /**
 * sideBarEnabled
 * boolean true or false
 * enable the sidebar (false by default)
 */

 var $sideBarEnabled = false;

 /**
 * defaultIcon
 * (String) Javascript definition of the default icon, standard Google Map marker icon
 * by default
 */
 var $defaultIcon = &quot;
 var gIcon = new GIcon();
 gIcon.image = \&quot;http://labs.google.com/ridefinder/images/mm_20_red.png\&quot;;
 gIcon.shadow = \&quot;http://labs.google.com/ridefinder/images/mm_20_shadow.png\&quot;;
 gIcon.iconSize = new GSize(12, 20);
 gIcon.shadowSize = new GSize(22, 20);
 gIcon.iconAnchor = new GLatLng(20, 6);
 gIcon.infoWindowAnchor = new GLatLng(1, 5);&quot;;

 /**
 * @var actionClick
 */
 var $actionClick = null;

 /**
 * @var $actionOver
 */
 var $actionOver = null;

 /**
 * $marker : Marker identifier
 * @var unknown_type
 */
 var $marker = null;

 /**
 * $dragndrop : Enable or disable drag &amp; drop
 * @var unknown_type
 */
 var $dragndrop = false;

 /**
 * $openWindowInformation : Enable or disable WindowInformation on markers
 */
 var $openWindowInformation = false;

 /**
 * Instanciation of a PhoogleMap object
 * @param $key Google Map Api Key
 * @return unknown_type
 */
 function __contruct ($key) {
 $this->apiKey = $key;
 }

 /**
 * return sidebarstatus
 */
 function isSideBarEnabled ()
 {
 return $this->sideBarEnabled;
 }

 /**
 * @function setDefaultIcon
 * @description Definition of a default icon
 */
 function setDefaultIcon ($definition)
 {
 $this->defaultIcon = $definition;
 }

 /**
 * @function setShowType
 * @description Enable or disable with a flag the control view
 * @param $flag
 * @return unknown_type
 */
 function setShowType ($flag)
 {
 $this->showType = $flag;
 }

 /**
 * @function getShowType
 * @desc Return the flag for control view
 * @param $flag
 * @return unknown_type
 */
 function getShowType ($flag)
 {
 return $this->showType;
 }

 /**
 * @function setZoomLevel
 * @param $level
 * @desc Change the zoom level
 * @return unknown_type
 */
 public function setZoomLevel ($level)
 {
 $this->zoomLevel = $level;
 }

 /**
 * @function getZoomLevel
 * @desc Return the zoom level
 * @return unknown_type
 */
 public function getZoomLevel ()
 {
 return $this->zoomLevel;
 }

 /**
 * @function addControlType
 * @description add the control type &quot;small&quot; or &quot;large&quot;
 * @param $controlType
 * @return unknown_type
 */
 public function addControlType ($controlType)
 {
 $this->controlType[] = $controlType;
 }

 /**
 * @function getControlType
 * @description get the control type &quot;small&quot; or &quot;large&quot;
 * @return $controlType
 */
 public function getType ()
 {
 return $this->controlType;
 }

 /**  Intelligent Zoom and resizing
 * @desc Reposition algorithm for rezoom and resizing fully automatized with an intelligence
 * @return unknown_type
 */
 public function enableAutoZoom ()
 {
 if (count($this->validPoints) <= 1)
 {
 return false;
 }
 $latitude_array = array();
 $latitude_array = array();
 foreach ($this->validPoints as $key => $value)
 {
 $latitude_array[] = $value['lat'];
 $longitude_array[] = $value['long'];
 }
 $minimal_latitude = min ($latitude_array);
 $maximal_latitude = max ($latitude_array);
 $minimal_longitude = min ($longitude_array);
 $maximal_longitude = max ($longitude_array);

 $central_latitude = $minimal_latitude + ($maximal_latitude - $minimal_latitude) / 2;
 $central_longitude = $minimal_longitude + ($maximal_longitude - $minimal_longitude) / 2;

 $miles = (3958.75 * acos(sin($minimal_latitude / 57.2958) * sin($maximal_latitude / 57.2958) + cos($minimal_latitude / 57.2958) * cos($maximal_latitude / 57.2958) * cos($maximal_longitude / 57.2958 - $minimal_longitude / 57.2958)));

 switch ($miles)
 {
 case ($miles < 0.2):
 $zoom = 2;
 break;
 case ($miles < 0.5):
 $zoom = 3;
 break;
 case ($miles < 1):
 $zoom = 3;
 break;
 case ($miles < 2):
 $zoom = 4;
 break;
 case ($miles < 3):
 $zoom = 5;
 break;
 case ($miles < 7):
 $zoom = 6;
 break;
 case ($miles < 15):
 $zoom = 8;
 break;

 case ($miles < 50):
 $zoom = 9;
 break;

 case ($miles < 300):
 $zoom = 12;
 break;

 case ($miles < 600):
 $zoom = 14;
 break;
 default:
 $zoom = 2;
 break;
 }

 $this->centerMap($central_latitude, $central_longitude);
 $this->zoomLevel = $zoom;

 }

 /**
 * @function getDefaultIcon
 * @return String Default Icon Definition
 */
 function getDefaultIcon ()
 {
 return $this->defaultIcon;
 }

 /**
 * @function setClickFunction
 * @desc Define the click event on a marker or on sidebar
 * @param Array:parameters
 * @return void
 */
 function setActionClick ($function)
 {
 $this->actionClick = $function;
 }

 /**
 * @function getActionClick
 * @desc return the click event
 * @return array: $this->actionClick
 */
 function getActionClick ()
 {
 return $this->actionClick;
 }

 /**
 * @function setActionOver
 * @desc Definition of an action when the mouse is over the marker
 * @return void
 */
 function setActionOver ($actionHover)
 {
 $this->actionOver = $actionHover;
 }

 /**
 * @function getActionHover
 * @desc Return an action when the mouse is over the marker
 * @return String
 */
 function getActionHover ()
 {
 return $this->actionOver;
 }

 /**
 * @function enableDragnDrop
 * @desc Enable drag &amp; drop on marker
 * @return void
 */
 function enableDragnDrop ()
 {
 $this->dragndrop = true;
 }

 /**
 * Enable OpenWindowInformation
 * @return unknown_type
 */
 function enableOpenWindowInformation ()
 {
 $this->openWindowInformation = true;
 }

 /**
 * @function defineDragnDropAction
 * @desc Define an action when somebody makes a drag &amp; drog on a marker
 * @return String
 */
 function defineDragnDropAction ($parameters)
 {
 $command = '';
 if ($this->sideBarEnabled == true &amp;&amp; $parameters['action'] == 'updateSideBar') {
 $command = '';
 }
 }

 /**
 * @function addGeoPoint
 * @description Add's an address to be displayed on the Google Map using latitude/longitude
 * early version of this function, considered experimental
 */

 function addGeoPoint($long, $lat, $address, $title, $infoHTML, $icon = null)
 {
 $pointer = count($this->validPoints);
 $this->validPoints[$pointer]['long'] = $long;
 $this->validPoints[$pointer]['lat'] = $lat;
 $this->validPoints[$pointer]['passedAddress'] = $address;
 $this->validPoints[$pointer]['title'] = $title;
 $this->validPoints[$pointer]['htmlMessage'] = $infoHTML;
 $this->validPoints[$pointer]['icon'] = $icon;
 }

 /**
 * @function centerMap
 * @description center's Google Map on a specific point
 * (thus eliminating the need for two different show methods from version 1.0)
 */

 function centerMap($lat,$long)
 {
 $this->centerMap = &quot;map.setCenter(new GLatLng(&quot;.$lat.&quot;,&quot;.$long.&quot;), &quot;.$this->zoomLevel.&quot;);\n&quot;;
 }

 /**
 * @function addAddress
 * @param $address:(string) Full and true address of the marker
 * @param $htmlMessage:(String) the HTML Code for Description of the Information Window
 * @param $iconURL:(String) The URL of the ICON
 * @returns Boolean Return false if the geocode is valid or true even
 * @description Add's an address to be displayed on the Google Map
 * (thus eliminating the need for two different show methods from version 1.0)
 */
 function addAddress($address, $title = null, $htmlMessage=null, $icon=null)
 {
 if (!is_string($address)){
 die(&quot;All Addresses must be passed as a string&quot;);
 }
 $apiURL = &quot;http://maps.google.com/maps/geo?&amp;output=xml&amp;oe=utf-8&amp;key=&quot;.$this->apiKey.&quot;&amp;q=&quot;;
 $address = $apiURL.urlencode($address);
 $addressData = file_get_contents($address);
 $results = $this->xml2array($addressData);
 $xml = simplexml_load_file($address);

 if($results['kml']['Response']['Status']['code'] === '602' || $results['kml']['Response']['Status']['code'] === '620') {
 return false;
 }
 if (empty($results['kml']['Response']['Placemark']['Point']['coordinates'])){
 $pointer = count($this->invalidPoints);

 $this->invalidPoints[$pointer]['lat']= $results['kml']['Response']['Placemark']['Point']['coordinates'][0];
 $this->invalidPoints[$pointer]['long']= $results['kml']['Response']['Placemark']['Point']['coordinates'][1];
 $this->invalidPoints[$pointer]['passedAddress'] = $address;
 $this->invalidPoints[$pointer]['title'] = $title;
 $this->invalidPoints[$pointer]['htmlMessage'] = $htmlMessage;
 $this->invalidPoints[$pointer]['icon'] = $icon;
 }else{
 $pointer = count($this->validPoints);
 $this->validPoints[$pointer]['lat']= $results['kml']['Response']['Placemark']['Point']['coordinates'];
 $this->validPoints[$pointer]['long']= $results['kml']['Response']['Placemark']['Point']['coordinates'];
 $this->validPoints[$pointer]['passedAddress'] = $address;
 $this->validPoints[$pointer]['title'] = $title;
 $this->validPoints[$pointer]['htmlMessage'] = $htmlMessage;
 $this->validPoints[$pointer]['icon'] = $icon;
 $this->validPoints[$pointer]['accuracy'] = null;
 $this->validPoints[$pointer]['address'] = trim($xml->Response->Placemark->address);
 $lat = explode(&quot;,&quot;,$this->validPoints[$pointer]['lat']);
 $long = explode(&quot;,&quot;,$this->validPoints[$pointer]['lat']);
 $this->validPoints[$pointer]['lat'] = $lat[1];
 $this->validPoints[$pointer]['long'] = $long[0];
 return array ('lat' => $lat[1], 'long' => $long[0], 'accuracy' => $this->validPoints[$pointer]['accuracy'], 'address' => $this->validPoints[$pointer]['address']);
 }
 }
 /**
 * @function showValidPoints
 * @param $displayType:string
 * @param $css_id:string
 * @returns nothing
 * @description Displays either a table or a list of the address points that are valid.
 * Mainly used for debugging but could be useful for showing a list of addresses
 * on the map
 */
 function showValidPoints($displayType,$css_id)
 {
 $total = count($this->validPoints);
 if ($displayType == &quot;table&quot;){
 echo &quot;<table id=\&quot;&quot;.$css_id.&quot;\&quot;>\n<tr>\n\t<td>Address</td>\n</tr>\n&quot;;
 for ($t=0; $t<$total; $t++){
 echo&quot;<tr>\n\t<td>&quot;.$this->validPoints[$t]['passedAddress'].&quot;</td>\n</tr>\n&quot;;
 }
 echo &quot;</table>\n&quot;;
 }
 if ($displayType == &quot;list&quot;){
 echo &quot;<ul id=\&quot;&quot;.$css_id.&quot;\&quot;>\n&quot;;
 for ($lst=0; $lst<$total; $lst++){
 echo &quot;<li>&quot;.$this->validPoints[$lst]['passedAddress'].&quot;</li>\n&quot;;
 }
 echo &quot;</ul>\n&quot;;
 }
 }

 /**
 * @function generateSideBar
 * @return nothing
 * @description Display a slidebar which generate dynamic links with Google Map
 */
 function generateSideBar ()
 {
 $total = count ($this->validPoints);
 $record = array ();
 foreach ($this->validPoints as $key => $value) {
 $entry = array ();

 // Here we recover all important informations
 $entry[] = '<a href=&quot;javascript:void(0);&quot; >'.$value['passedAddress'].'</a>';
 $entry[] = $value['title'];
 $record[] = $entry;
 }
 $this->sideBarEnabled = true;
 return $record;
 }

 /**
 * @static function generateIcon
 * @param $url (String) URL of the icon
 * @param $shadow (String) URL of the icon's shadow
 * @param $iconSize (Array (height, width)) icon's dimensions
 * @param $shadowSize (Array (height, width)) shadow icon's dimensions
 * @param $iconAnchor (Array (height, width)) Icon Anchor
 * @param $infoWindowAnchor (Array (height, width)) infoWindowAnchor
 * @return nothing
 * @description Generate javascript to make a marker icon
 */
 static function generateIcon ($url, $shadow = null, $iconSize, $shadowSize = array ('height' => 0, 'width' => 0), $iconAnchor = array ('height' => 0, 'width' => 0), $infoWindowAnchor = array('height' => 5, 'width' => 5))
 {
 return &quot;
 var gIcon = new GIcon();
 gIcon.image = \&quot;&quot;.$url.&quot;\&quot;;
 gIcon.shadow = \&quot;&quot;.$shadow.&quot;.\&quot;;
 gIcon.iconSize = new GSize(&quot;.$iconSize['height'].&quot;, &quot;.$iconSize['width'].&quot;);
 gIcon.shadowSize = new GSize(&quot;.$shadowSize['height'].&quot;,&quot;.$shadowSize['width'].&quot;);
 gIcon.iconAnchor = new GLatLng(&quot;.$iconAnchor['height'].&quot;, &quot;.$iconAnchor['width'].&quot;);
 gIcon.infoWindowAnchor = new GLatLng(&quot;.$infoWindowAnchor['height'].&quot;, &quot;.$infoWindowAnchor['width'].&quot;);&quot;;

 }

 /**
 * @function showInvalidPoints
 * @param $displayType:string
 * @param $css_id:string
 * @returns nothing
 * @description Displays either a table or a list of the address points that are invalid.
 * Mainly used for debugging shows only the points that are NOT on the map
 */
 function showInvalidPoints($displayType,$css_id)
 {
 $total = count($this->invalidPoints);
 if ($displayType == &quot;table&quot;){
 echo &quot;<table id=\&quot;&quot;.$css_id.&quot;\&quot;>\n<tr>\n\t<td>Address</td>\n</tr>\n&quot;;
 for ($t=0; $t<$total; $t++){
 echo&quot;<tr>\n\t<td>&quot;.$this->invalidPoints[$t]['passedAddress'].&quot;</td>\n</tr>\n&quot;;
 }
 echo &quot;</table>\n&quot;;
 }
 if ($displayType == &quot;list&quot;){
 echo &quot;<ul id=\&quot;&quot;.$css_id.&quot;\&quot;>\n&quot;;
 for ($lst=0; $lst<$total; $lst++){
 echo &quot;<li>&quot;.$this->invalidPoints[$lst]['passedAddress'].&quot;</li>\n&quot;;
 }
 echo &quot;</ul>\n&quot;;
 }
 }
 /**
 * @function setWidth
 * @param $width:int
 * @returns nothing
 * @description Sets the width of the map to be displayed
 */
 function setWidth($width)
 {
 $this->mapWidth = $width;
 }
 /**
 * @function setHeight
 * @param $height:int
 * @returns nothing
 * @description Sets the height of the map to be displayed
 */
 function setHeight($height)
 {
 $this->mapHeight = $height;
 }
 /**
 * @function setAPIkey
 * @param $key:string
 * @returns nothing
 * @description Stores the API Key acquired from Google
 */
 function setAPIkey($key)
 {
 $this->apiKey = $key;
 }
 /**
 * @function printGoogleJS
 * @returns nothing
 * @description Adds the necessary Javascript for the Google Map to function
 * should be called in between the html <head></head> tags
 */
 function printGoogleJS()
 {
 echo &quot;\n<script src=\&quot;http://maps.google.com/maps?file=api&amp;v=2&amp;key=&quot;.$this->apiKey.&quot;\&quot; type=\&quot;text/javascript\&quot;></script>\n&quot;;
 }

 /**
 * showMap
 * enhance the view of the map on a PHP Template
 * @return HTML Code
 */
 function showMap()
 {
 if (empty($this->validPoints)) {
 return false;
 }

 echo &quot;\n<div id=\&quot;map\&quot; style=\&quot;width: &quot;.$this->mapWidth.&quot;px; height: &quot;.$this->mapHeight.&quot;px\&quot;>\n</div>\n&quot;;
 echo &quot; <script type=\&quot;text/javascript\&quot;>\n
 function showmap(){
 //<![CDATA[\n
 if (GBrowserIsCompatible()) {\n
 var map = new GMap2(document.getElementById(\&quot;map\&quot;));\n&quot;;
 if (empty($this->centerMap)){
 echo &quot;map.setCenter(new GLatLng(&quot;.$this->validPoints[0]['lat'].&quot;,&quot;.$this->validPoints[0]['long'].&quot;), &quot;.$this->zoomLevel.&quot;);\n&quot;;
 }else{
 echo $this->centerMap;
 }
 if (!empty($this->zoomLevel))
 {
 echo &quot;map.setZoom(&quot;.$this->zoomLevel.&quot;);&quot;;
 }

 echo &quot;}\n&quot;;
 if ($this->showControl){
 foreach ($this->controlType as $key => $value) {
 if ($this->controlType[$key] == 'small'){echo &quot;map.addControl(new GSmallMapControl());\n&quot;;}
 if ($this->controlType[$key] == 'large'){echo &quot;map.addControl(new GLargeMapControl());\n&quot;;}
 if ($this->controlType[$key] == 'smallzoom') {echo &quot;map.addControl(new GSmallZoomControl());\n&quot;;}
 if ($this->controlType[$key] == 'smallzoom3d'){echo &quot;map.addControl(new GSmallZoomControl3D());\n&quot;;}
 if ($this->controlType[$key] == 'scale') {echo &quot;map.addControl(new GScaleControl());\n&quot;;}
 if ($this->controlType[$key] == 'large3d') {echo &quot;map.addControl(new GLargeMapControl3D());\n&quot;;}
 if ($this->controlType[$key] == 'navlabel') {echo &quot;map.addControl(new GNavLabelControl());\n&quot;;}
 if ($this->controlType[$key] == 'overview') {echo &quot;map.addControl(new GOverviewMapControl());\n&quot;;}
 if ($this->controlType[$key] == 'hierarchical') {echo &quot;map.addControl(new GHierarchicalMapTypeControl());\n&quot;;}
 }
 }

 if ($this->showType){
 echo &quot;map.addControl(new GMapTypeControl());\n&quot;;
 }

 $numPoints = count($this->validPoints);

 // Getting the sidebar
 echo &quot;var sideBar = document.getElementById(\&quot;sideBar\&quot;);&quot;;

 for ($g = 0; $g<$numPoints; $g++){

 // Custom icon generated if declare
 if ($this->validPoints[$g]['icon']) {
 echo $this->validPoints[$g]['icon'];
 } else {
 echo $this->defaultIcon;
 }
 echo &quot;var point&quot;.$g.&quot; = new GLatLng(&quot;.$this->validPoints[$g]['lat'].&quot;,&quot;.$this->validPoints[$g]['long'].&quot;)\n;
var marker&quot;.$g.&quot; = new GMarker(point&quot;.$g.&quot;, {draggable: true, icon:gIcon});\n
map.addOverlay(marker&quot;.$g.&quot;)\n
var gInfoMarker&quot;.$g.&quot; = \&quot;&quot;.$this->validPoints[$g]['htmlMessage'].&quot;\&quot; \n;
var gTitle&quot;.$g.&quot; = \&quot;&quot;.$this->validPoints[$g]['title'].&quot;\&quot; \n&quot;;

 // Sidebar generation if declare
 if ($this->sideBarEnabled == true) {
 echo &quot;
 var newLabel = document.createElement(\&quot;div\&quot;);
 newLabel.innerHTML = \&quot;<a id=marker&quot;.$g.&quot; href=# > \&quot; + gTitle&quot;.$g.&quot; + \&quot; </a> \&quot;;
 sideBar.appendChild (newLabel);
 var marker = document.getElementById (\&quot;marker&quot;.$g.&quot;\&quot;);
 marker.onclick = function(){GEvent.trigger(marker&quot;.$g.&quot;,'click'); return false};
 marker.onmouseover = function() {GEvent.trigger(marker&quot;.$g.&quot;, 'mouseover'); return false};
 marker.onmouseout = function() {GEvent.trigger(marker&quot;.$g.&quot;, 'mouseout'); return false};
 \n
 &quot;;
 }

 // Open WindowInformation without actions
 if ($this->openWindowInformation == true)
 {
 echo &quot;marker&quot;.$g.&quot;.openInfoWindowHtml(gInfoMarker&quot;.$g.&quot;);\n&quot;;
 }

 // Run the action defined
 echo &quot;GEvent.addListener(marker&quot;.$g.&quot;, \&quot;click\&quot;, function() {\n&quot;;
 if ($this->validPoints[$g]['htmlMessage']!=null){
 if ($this->actionClick[&quot;type&quot;] == &quot;link&quot;) {
 echo 'window.parent.location.replace(&quot;'.$this->actionClick[&quot;url&quot;].'&quot;)';
 }

 if ($this->actionClick[&quot;type&quot;] == &quot;openInfoWindow&quot;) {
 echo &quot;marker&quot;.$g.&quot;.openInfoWindowHtml(gInfoMarker&quot;.$g.&quot;);\n&quot;;
 }
 }

 echo &quot;});\n&quot;;
 if ($this->openWindowInformation !== true) {
 // Execute l'action définie lorsqu'on survole un marqueur
 echo &quot;GEvent.addListener(marker&quot;.$g.&quot;, \&quot;mouseover\&quot;, function() {\n&quot;;
 if ($this->validPoints[$g]['htmlMessage']!=null){
 if ($this->actionOver['type'] == &quot;openInfoWindow&quot;) {
 echo &quot;marker&quot;.$g.&quot;.openInfoWindowHtml(gInfoMarker&quot;.$g.&quot;);\n&quot;;
 }
 }

 echo &quot;});\n&quot;;

 // Execute the action when the mouse is over a marker
 echo &quot;GEvent.addListener(marker&quot;.$g.&quot;, \&quot;mouseout\&quot;, function() {\n&quot;;
 if ($this->validPoints[$g]['htmlMessage']!=null){
 if ($this->actionOver['type'] == &quot;openInfoWindow&quot;) {
 echo &quot;marker&quot;.$g.&quot;.closeInfoWindow();\n&quot;;
 }
 }
 echo &quot;});\n&quot;;
 }

 // Execute an action when the user drag &amp; drop a marker
 if ($this->dragndrop == true) {
 echo &quot;GEvent.addListener(marker&quot;.$g.&quot;, \&quot;dragstart\&quot;, function () {\n&quot;;

 echo &quot;});\n&quot;;
 echo &quot;GEvent.addListener(marker&quot;.$g.&quot;, \&quot;dragend\&quot;, function() {

 });&quot;;
 }

 }

 echo &quot; //]]>\n
 }&quot;;
 // Display the map
 echo &quot;window.onload = showmap;&quot;;

 echo &quot;</script>\n&quot;;
 }

 /**
 * XML Parsing Engine
 * @param string $xml
 * @return array $xmlarray
 */
 function xml2array($xml)
 {
 $this->depth=-1;
 $this->xml_parser = xml_parser_create();
 xml_set_object($this->xml_parser, $this);
 xml_parser_set_option ($this->xml_parser,XML_OPTION_CASE_FOLDING, 0);//Don't put tags uppercase
 xml_set_element_handler($this->xml_parser, &quot;startElement&quot;, &quot;endElement&quot;);
 xml_set_character_data_handler($this->xml_parser,&quot;characterData&quot;);
 xml_parse($this->xml_parser,$xml,true);
 xml_parser_free($this->xml_parser);
 return $this->arrays[0];
 }

 /**
 * XML Parsing Method StartElement
 * @param $parser
 * @param $name
 * @param $attrs
 * @return unknown_type
 */
 function startElement($parser, $name, $attrs)
 {
 $this->keys[]=$name;
 $this->attrs[] = $attrs;
 $this->node_flag=1;
 $this->depth++;
 }

 /**
 * characterData
 * @param $parser
 * @param $data
 * @return unknown_type
 */
 function characterData($parser,$data)
 {
 if(!trim($data)) return;
 $key=end($this->keys);
 $this->arrays[$this->depth][$key]=$data;
 $this->node_flag=0;
 }

 /**
 * endElement
 * @param $parser
 * @param $name
 * @return unknown_type
 */
 function endElement($parser, $name)
 {
 $key=array_pop($this->keys);
 if($this->node_flag==1){
 $this->arrays[$this->depth][$key]=$this->arrays[$this->depth+1];

 $this->arrays[$this->depth+1] = null;
 // unset($this->arrays[$this->depth+1]);

 }

 $this->node_flag=1;
 $this->depth--;
 }
}
?>