Phoogle php class

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Beezz

Beezz

09/07/2009 10:54:00
Quote Anchor link
DIt is de code en ik wil het werkend zien te krijgen op mijn website.

Weet iemand hoe ik deze class werkende krijg???


Snap er niks meer van...

Waar het vandaan komt wordt er gezegd dat het maar 5 lines of code zijn..

Maar welke code dat is kun je nergens vinden..

alvast bedankt...

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php

/**
* Phoogle Maps 2.0 | Uses Google Maps API to create customizable maps
* that can be embedded on your website
*    Copyright (C) 2005  Justin Johnson
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*
* Phoogle Maps 2.0
* Uses Google Maps Mapping API to create customizable
* Google Maps that can be embedded on your website
*
* @class        Phoogle Maps 2.0
* @author       Justin Johnson <[email protected]>
* @copyright    2005 system7designs
*/





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 = "";

/**
* 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 = 'small';
    
/**
* zoomLevel
* int: 0-17
* set's the initial zoom level of the map
*/


    var $zoomLevel = 4;




/**
* @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($lat,$long,$infoHTML){
    $pointer = count($this->validPoints);
        $this->validPoints[$pointer]['lat'] = $lat;
        $this->validPoints[$pointer]['long'] = $long;
        $this->validPoints[$pointer]['htmlMessage'] = $infoHTML;
    }

    
/**
* @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 = "map.centerAndZoom(new GPoint(".$long.",".$lat."), ".$this->zoomLevel.");\n";
}

    
    
/**
* @function     addAddress
* @param        $address:string
* @returns      Boolean True:False (True if address has long/lat, false if it doesn't)
* @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,$htmlMessage=null){
     if (!is_string($address)){
        die("All Addresses must be passed as a string");
      }

        $apiURL = "http://maps.google.com/maps/geo?&output=xml&key=".$this->apiKey."&q=";
        $addressData = file_get_contents($apiURL.urlencode($address));
        
        $results = $this->xml2array(utf8_encode($addressData));
        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]['htmlMessage'] = $htmlMessage;
          }
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]['htmlMessage'] = $htmlMessage;
        }
    
    
    }

/**
* @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 == "table"){
        echo "<table id=\"".$css_id."\">\n<tr>\n\t<td>Address</td>\n</tr>\n";
        for ($t=0; $t<$total; $t++){
            echo"<tr>\n\t<td>".$this->validPoints[$t]['passedAddress']."</td>\n</tr>\n";
        }

        echo "</table>\n";
        }

      if ($displayType == "list"){
        echo "<ul id=\"".$css_id."\">\n";
      for ($lst=0; $lst<$total; $lst++){
        echo "<li>".$this->validPoints[$lst]['passedAddress']."</li>\n";
        }

        echo "</ul>\n";
       }
    }

/**
* @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 == "table"){
        echo "<table id=\"".$css_id."\">\n<tr>\n\t<td>Address</td>\n</tr>\n";
        for ($t=0; $t<$total; $t++){
            echo"<tr>\n\t<td>".$this->invalidPoints[$t]['passedAddress']."</td>\n</tr>\n";
        }

        echo "</table>\n";
        }

      if ($displayType == "list"){
        echo "<ul id=\"".$css_id."\">\n";
      for ($lst=0; $lst<$total; $lst++){
        echo "<li>".$this->invalidPoints[$lst]['passedAddress']."</li>\n";
        }

        echo "</ul>\n";
       }
    }

/**
* @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 "\n<script src=\"http://maps.google.com/maps?file=api&v=2&key=".$this->apiKey."\" type=\"text/javascript\"></script>\n";
    }

/**
* @function     showMap
* @description  Displays the Google Map on the page
*/

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

            echo "}\n
            var icon = new GIcon();
            icon.image = \"http://labs.google.com/ridefinder/images/mm_20_red.png\";
            icon.shadow = \"http://labs.google.com/ridefinder/images/mm_20_shadow.png\";
            icon.iconSize = new GSize(12, 20);
            icon.shadowSize = new GSize(22, 20);
            icon.iconAnchor = new GPoint(6, 20);
            icon.infoWindowAnchor = new GPoint(5, 1);
            
            "
;
        if ($this->showControl){
          if ($this->controlType == 'small'){echo "map.addControl(new GSmallMapControl());\n";}
          if ($this->controlType == 'large'){echo "map.addControl(new GLargeMapControl());\n";}
        
            }

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

    
    $numPoints = count($this->validPoints);
    for ($g = 0; $g<$numPoints; $g++){
        echo "var point".$g." = new GPoint(".$this->validPoints[$g]['long'].",".$this->validPoints[$g]['lat'].")\n;
              var marker"
.$g." = new GMarker(point".$g.");\n
              map.addOverlay(marker"
.$g.")\n
              GEvent.addListener(marker"
.$g.", \"click\", function() {\n";
              if ($this->validPoints[$g]['htmlMessage']!=null){
              echo "marker".$g.".openInfoWindowHtml(\"".$this->validPoints[$g]['htmlMessage']."\");\n";
              }
else{
             echo "marker".$g.".openInfoWindowHtml(\"".$this->validPoints[$g]['passedAddress']."\");\n";
                }

              echo "});\n";
    }

        echo "        //]]>\n
        }
        window.onload = showmap;
        </script>\n"
;
        }

 ///////////THIS BLOCK OF CODE IS FROM Roger Veciana's CLASS (assoc_array2xml) OBTAINED FROM PHPCLASSES.ORG//////////////
       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, "startElement", "endElement");
        xml_set_character_data_handler($this->xml_parser,"characterData");
        xml_parse($this->xml_parser,$xml,true);
        xml_parser_free($this->xml_parser);
        return $this->arrays[0];

    }
    function
startElement($parser, $name, $attrs){
           $this->keys[]=$name;
           $this->node_flag=1;
           $this->depth++;
     }
    function
characterData($parser,$data){
       $key=end($this->keys);
       $this->arrays[$this->depth][$key]=$data;
       $this->node_flag=0;
     }
    function
endElement($parser, $name)
     {

       $key=array_pop($this->keys);
       if($this->node_flag==1){
         $this->arrays[$this->depth][$key]=$this->arrays[$this->depth+1];
         unset($this->arrays[$this->depth+1]);
       }

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

//////////////////END CODE FROM Roger Veciana's CLASS (assoc_array2xml) /////////////////////////////////


}//End Of Class


?>
 
PHP hulp

PHP hulp

19/04/2024 21:32:31
 
- Ariën  -
Beheerder

- Ariën -

09/07/2009 11:01:00
Quote Anchor link
Aan die class hoef je niet te zitten.
Met een auto ga je ook nooit onder de motorkap je motor 'besturen' om harder te gaan.

Op hun site: http://www.systemsevendesigns.com/phoogle staan gewoon examples verder.
Gewijzigd op 01/01/1970 01:00:00 door - Ariën -
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.