-
Notifications
You must be signed in to change notification settings - Fork 9
/
markers_clustering.php
58 lines (47 loc) · 1.89 KB
/
markers_clustering.php
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
<?php
// This is just for my examples
require( '_system/config.php' );
$relevant_code = array(
'\PHPGoogleMaps\Overlay\Marker',
'\PHPGoogleMaps\Overlay\MarkerDecorator'
);
// Autoloader stuff
require( '_system/autoload.php' );
$map = new \PHPGoogleMaps\Map;
$map->setWidth( 800 );
$map->setHeight( 400 );
$map->setZoom( 2 );
$map->disableAutoEncompass();
$map->setCenterCoords( 39.91, 116.38 );
// Get the photo data from the marker cluster page
$json = json_decode( str_replace( 'var data = ', '', file_get_contents( 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/data.json' ) ) );
// Add 1000 markers using the lat/lng from the photo data
for ( $i=0;$i<1000;$i++ ) {
$marker = \PHPGoogleMaps\Overlay\Marker::createFromPosition( new \PHPGoogleMaps\Core\LatLng( $json->photos[$i]->latitude, $json->photos[$i]->longitude ) );
$marker->setContent( sprintf( '<img src="%s" style="width: 200px">', $json->photos[$i]->photo_file_url ) );
$map->addObject( $marker );
}
// Set cluster options
$cluster_options = array(
'maxZoom' => 10,
'gridSize' => null
);
$map->enableClustering( '_js/markerclusterer.js', $cluster_options );
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Marker Clustering - <?php echo PAGE_TITLE ?></title>
<link rel="stylesheet" type="text/css" href="_css/style.css">
<?php $map->printHeaderJS() ?>
<?php $map->printMapJS() ?>
</head>
<body>
<h1>Marker Clustering</h1>
<p>Marker clustering is provided by the <a href="http://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries">Google Maps utility library</a>.</p>
<p>This example was taken from <a href="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/examples/advanced_example.html">this page</a></p>
<?php require( '_system/nav.php' ) ?>
<?php $map->printMap() ?>
</body>
</html>