forked from tuupola/php_google_maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.html
205 lines (156 loc) · 5.77 KB
/
cluster.html
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
<?php
require_once 'Cache/Lite.php';
require_once 'Benchmark/Timer.php';
$options = array(
'lifeTime' => 3600000
);
$cache = new Cache_Lite();
if ($data = $cache->get($_SERVER['REQUEST_URI'])) {
print $data;
die();
}
ob_start();
$timer = new Benchmark_Timer(true);
$timer->start();
require_once 'Google/Maps.php';
$map = Google_Maps::create('static');
$map->setKey(trim(file_get_contents('api_key.txt')));
$map->setSize('540x300');
$map->setType('terrain');
$zoom = Google_Maps_Control::create('zoom');
$map->addControl($zoom);
$pan = Google_Maps_Control::create('pan');
$map->addControl($pan);
$timer->setMarker('Start loading KML');
$xml = simplexml_load_file('cities.kml', null, LIBXML_NOCDATA);
$timer->setMarker('KML loaded');
foreach ($xml->Document->Placemark as $placemark) {
list($longitude, $latitude, $elevation) = explode(',', $placemark->Point->coordinates, 3);
$coordinate = new Google_Maps_Coordinate($latitude, $longitude);
$marker = new Google_Maps_Marker($coordinate);
$marker->setSize('small');
$marker->setColor('blue');
/*
$bubble = new Google_Maps_Infowindow($placemark->description);
$bubble->setMarker($marker);
$map->addInfowindow($bubble);
*/
$map->addMarker($marker);
}
$timer->setMarker('Markers created');
$map->zoomToFit();
$timer->setMarker('Zoom calculated');
$map->setProperties($_GET);
$clusterer = Google_Maps_Clusterer::create('distance');
$map->setClusterer($clusterer);
//$map->getClusteredMarkers('string', $map->getBounds());
$timer->setMarker('Clustered');
$timer->stop();
//$timer->display();
//print $map->toUrl();
//die();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Clustered Markers With Static Maps Demo</title>
<link href="http://www.appelsiini.net/stylesheets/screen.css" rel="stylesheet" type="text/css" />
<link href="http://www.appelsiini.net/stylesheets/main.css" rel="stylesheet" type="text/css" />
<link href="css/controls.css" rel="stylesheet" type="text/css" />
<link href="css/infowindow.css" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/atom+xml" href="http://feeds.feedburner.com/tuupola" title="Atom feed" />
</head>
<body>
<div class="container">
<!-- header -->
<div id="header" class="span-20">
<div class="span-11">
<h1>PHP Google Static Maps</h1><br />
<p>Programmatically Create Google Static Maps With PHP.</p>
</div>
<div class="span-9 last">
<ul id="nav">
<li id="first"><a href="http://www.appelsiini.net/">weblog</a></li>
<li><a href="http://www.appelsiini.net/projects" class="last">projects</a></li>
<!--
<li><a href="http://www.appelsiini.net/cv" class="last">cv</a></li>
-->
</ul>
</div>
</div>
<!-- /header -->
<!-- content -->
<div class="span-14" id="content">
<div class="entry">
<div class="entrytitle">
<h2>Clustered Markers With Static Maps</h2>
<h4>There is no JavaScript in this page (except Google Analytics)</h4>
</div>
<p>
</p>
<div class="entrybody">
<?php print $map->toHtml(); ?>
<br /><br />
<p>
Markers are created from <a href="http://www.appelsiini.net/projects/php_google_maps/cities.kml">KML</a>. Markers are clustered using
<a href="http://www.appelsiini.net/2008/11/introduction-to-marker-clustering-with-google-maps">distance based clustering</a>.
Zooming and panning works. There is no JavaScript (except Google Analytics) used in this page.
Map is created using following code:
</p>
<p>
<pre>require_once 'Google/Maps.php';
require_once 'Google/Maps.php';
$map = Google_Maps::create('static');
$map->setKey(API_KEY);
$map->setSize('540x300');
$map->setType('terrain');
$zoom = Google_Maps_Control::create('zoom');
$map->addControl($zoom);
$pan = Google_Maps_Control::create('pan');
$map->addControl($pan);
$clusterer = Google_Maps_Clusterer::create('distance');
$map->setClusterer($clusterer);
$xml = simplexml_load_file('cities.kml', null, LIBXML_NOCDATA);
foreach ($xml->Document->Placemark as $placemark) {
list($longitude, $latitude, $elevation) =
explode(',', $placemark->Point->coordinates, 3);
$coordinate = new Google_Maps_Coordinate($latitude, $longitude);
$marker = new Google_Maps_Marker($coordinate);
$marker->setSize('small');
$marker->setColor('blue');
}
$map->zoomToFit();
$map->setProperties($_GET);</pre>
<h3>Where's the Source?</h3>
<p>
Code uses work in progress <a href="http://github.com/tuupola/php_google_maps/tree">Simple Static Maps PHP class</a>.
It aims to make working with static maps jolly good. Code is still alpha quality.
API might change any time. Use at your own risk.
</p>
<p>
If you like this you might also want to see <a href="http://www.appelsiini.net/2008/10/simple-zoom-and-pan-controls-with-static-maps">walkthrough</a> and <a href="http://www.appelsiini.net/2008/10/simple-static-maps-with-php">other features</a>.
</p>
</div>
</div>
<hr class="space" />
</div>
<!-- /content -->
<!-- sidebar -->
<div class="span-5 push-1 last" id="sidebar">
<br /><br />
<a href="http://twitter.com/tuupola"><img src="http://www.appelsiini.net/images/twitter3.png" alt="@tuupola" /></a>
</div>
<!-- /sidebar -->
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">
_uacct = "UA-190966-1";
urchinTracker();
</script>
</body>
</html>
<?php
$data = ob_get_contents();
$cache->save($data);
?>