get($_SERVER['REQUEST_URI']) && false) { print "HIT"; 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'); $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(); ?> Clustered Markers With Static Maps Demo

Clustered Markers With Static Maps

There is no JavaScript in this page (except Google Analytics)

toHtml(); ?>

Markers are created from KML. Markers are clustered using distance based clustering. Zooming and panning works. There is no JavaScript (except Google Analytics) used in this page. Map is created using following code:

require_once 'Google/Maps.php';

require_once 'Google/Maps.php';
$map = Google_Maps::create('static');

$map->setKey(API_KEY);$map->setSize('540x300');

$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);

Where's the Source?

Code uses work in progress Simple Static Maps PHP class. 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.

If you like this you might also want to see walkthrough and other features.


save($data); ?>