root/trunk/example.php

Revision 26, 3.5 KB (checked in by m, 3 years ago)

Fixed some errors with float to string conversion. Updated example.

  • Property svn:keywords set to Id Rev
Line 
1<?php
2
3// +----------------------------------------------------------------------+
4// | Class for creating personalized interactive maps with Google Maps    |
5// +----------------------------------------------------------------------+
6// | Copyright (C) 2005 Markus Tacker <m@tacker.org>                      |
7// +----------------------------------------------------------------------+
8// | This library is free software; you can redistribute it and/or        |
9// | modify it under the terms of the GNU Lesser General Public           |
10// | License as published by the Free Software Foundation; either         |
11// | version 2.1 of the License, or (at your option) any later version.   |
12// |                                                                      |
13// | This library is distributed in the hope that it will be useful,      |
14// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
16// | Lesser General Public License for more details.                      |
17// |                                                                      |
18// | You should have received a copy of the GNU Lesser General Public     |
19// | License along with this library; if not, write to the                |
20// | Free Software Foundation, Inc.                                       |
21// | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA               |
22// +----------------------------------------------------------------------+
23
24/**
25* This example lists a few Points of Interest to a Map of Miami South beach
26*/
27
28require_once 'Google/Map.php';
29require_once 'HTML/Page2.php';
30require_once 'HTML/Table.php';
31
32// Create a new map for http://projects.tacker.org/Google_Map/example.php
33// An API Key for your domain can be created here: http://www.google.com/apis/maps/signup.html
34$Map = new Google_Map('ABQIAAAAKyAGN22UGBg-i1P7zOS9ehR4smpzJw-CC7VmpNLRWXBOiLFhjhTu3fsgy52NL3P1BzgYORUov30VZQ');
35$Map->addControl(GOOGLE_MAP_CONTROL_SCALE);
36$Map->addControl(GOOGLE_MAP_CONTROL_LARGE_MAP);
37$Map->addControl(GOOGLE_MAP_CONTROL_MAP_TYPE);
38// $Map->addControl(GOOGLE_MAP_CONTROL_OVERVIEW_CONTROL);
39$Map->click_callback = 'clickPoint';
40$Map->fromLink('http://maps.google.com/?om=1&t=k&ll=50.095019,8.762163&spn=0.002271,0.005');
41// Set up the starting ccordinates
42// $Map->longitude = 50.095019;
43// $Map->latitude = 8.762163;
44// Use a higher zoom level
45// $Map->zoom_level = 19;
46// Add markers
47$Map->addMarker('50.0950328073255', '8.762154579162598', 'My Home', '<a href="http://m.tacker.org/">m.tacker.org</a>');
48// Just echo the whole Page
49// $Map->display();
50
51// Create a HTML page
52$HTML = new HTML_Page2;
53$HTML->setTitle('PEAR::Google_Map Example');
54$HTML->addScriptDeclaration('function clickPoint(point) { alert("This point was clicked: " + point.lat() + " (latitude), " + point.lng() + " (longitude)."); }');
55// Add the map
56$HTML->addBodyContent($Map->toHTML());
57// Add the POI listing
58$Table = new HTML_Table();
59$Table->setAutoGrow(true);
60$n = 0;
61$Table->setHeaderContents($n, 0, 'Icon');
62$Table->setHeaderContents($n, 1, 'Name');
63foreach ($Map->getMarkers() as $marker) {
64    $n++;
65    $Table->setCellContents($n, 0, '<img src="' . $marker['icon'] . '" />');
66    $name = $marker['name'];
67    if (!empty($marker['description'])) {
68        $name .= '<br />' . $marker['description'];
69    }
70    $Table->setCellContents($n, 1, $name);
71}
72$HTML->addBodyContent($Table->toHTML());
73// Display the page
74$HTML->display();
75
76?>
Note: See TracBrowser for help on using the browser.