<?php // This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Overlay\\Marker'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $map = new \PHPGoogleMaps\Map(); $marker1 = \PHPGoogleMaps\Overlay\Marker::createFromLocation('New York, NY', array('title' => 'New York, NY', 'content' => 'New York marker')); $marker2 = \PHPGoogleMaps\Overlay\Marker::createFromPosition(new \PHPGoogleMaps\Core\LatLng(32.7153292, -117.1572551), array('title' => 'San Diego, CA', 'content' => 'San Diego marker')); $marker3 = \PHPGoogleMaps\Overlay\Marker::createFromLocation('Dallas, TX', array('title' => 'Dallas, TX', 'content' => 'Dallas marker')); $map->addObjects(array($marker1, $marker2, $marker3)); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Sidebar - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <style type="text/css"> #map, #map_sidebar { float: left } .sidebar { list-style:none; margin:0 0 0 10px;padding:0;width: 200px; } .sidebar li { margin-bottom: 2px; } .sidebar p { background-color: #eee;margin:0; padding: 5px;cursor: pointer; } .sidebar p:hover { background-color: #ddd; }
$map_loader->register(); // If location is set if (isset($_GET['location']) && strlen($_GET['location'])) { // Create a PDO Geocode Cache connection and pass it to the caching geocoder try { $geoPDO = new \PHPGoogleMaps\Service\GeocodeCachePDO('localhost', 'username', 'password', 'database'); } catch (PDOException $e) { die('Unable to connect to database'); } $caching_geo = new \PHPGoogleMaps\Service\CachingGeocoder($geoPDO); // Geocode the location with the caching geocoded $geocode_result = $caching_geo->geocode($_GET['location']); if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) { // Create a map $map = new \PHPGoogleMaps\Map(); $marker = \PHPGoogleMaps\Overlay\Marker::createFromPosition($geocode_result); $map->addObject($marker); $map->disableAutoEncompass(); $map->setZoom(13); $map->setCenter($geocode_result); } else { $location = $geocode_result->location; $error = $geocode_result->error; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8">
$relevant_code = array('\\PHPGoogleMaps\\Overlay\\Marker', '\\PHPGoogleMaps\\Overlay\\MarkerDecorator'); // Autoloader stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $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('http://www.galengrover.com/projects/php-google-maps/examples/_js/markerclusterer.js', $cluster_options); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Marker Clustering - <?php echo PAGE_TITLE; ?>
$location_options = $geocode_result->response->results; } else { $position = $geocode_result; } } else { $location = $geocode_result->location; $error = $geocode_result->error; } } if (isset($_GET['geocoded_location'])) { list($location, $lat, $lng) = explode('|', $_GET['geocoded_location']); $position = new \PHPGoogleMaps\Core\LatLng($lat, $lng, $location); } if (isset($position)) { $map = new \PHPGoogleMaps\Map(); $marker = \PHPGoogleMaps\Overlay\Marker::createFromPosition($position, array('content' => $position->location)); $map->addObject($marker); $map->disableAutoEncompass(); $map->setZoom(13); $map->setCenter($position); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Geocoding - <?php echo PAGE_TITLE; ?> </title>
// This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Overlay\\Polygon', '\\PHPGoogleMaps\\Overlay\\Poly', '\\PHPGoogleMaps\\Overlay\\PolyDecorator'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); use PHPGoogleMaps\Service\Geocoder; $map = new \PHPGoogleMaps\Map(); // Array of polygons $polygon_paths = array(Geocoder::geocode('San Diego, CA'), 'Austin, TX', Geocoder::geocode('New Haven, CT'), Geocoder::geocode('Seattle, WA')); $polygon_options = array('strokeColor' => '#0000ff', 'fillColor' => '#230754', 'clickable' => false); $polygon = new \PHPGoogleMaps\Overlay\Polygon($polygon_paths, $polygon_options); $polygon->addPath('San Francisco, CA'); $marker_options = array('title' => 'Center of Polygon', 'content' => 'This marker was added to the center of the polygon via Polygon::getCenter()'); $marker = \PHPGoogleMaps\Overlay\Marker::createFromPosition($polygon->getCenter(), $marker_options); $map->disableAutoEncompass(); $map->setCenter('Austin, TX'); $map->setZoom(3); $polygon_map = $map->addObject($polygon); $map->addObject($marker); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Polygons - <?php echo PAGE_TITLE; ?> </title>
<?php // This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Overlay\\Marker', '\\PHPGoogleMaps\\Overlay\\MarkerDecorator'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $map = new \PHPGoogleMaps\Map(); $marker1_options = array('title' => 'New York, NY', 'content' => '<p><strong>New York, NY info window</strong></p>'); $marker1 = \PHPGoogleMaps\Overlay\Marker::createFromLocation('New York, NY', $marker1_options); $marker2_options = array('title' => 'San Diego, CA', 'content' => '<p><strong>San Diego, CA info window</strong></p>'); $marker2 = \PHPGoogleMaps\Overlay\Marker::createFromPosition(new \PHPGoogleMaps\Core\LatLng(32.7153292, -117.1572551), $marker2_options); // Add both markers to the map // We need to be able to remove marker1 so we get a decorator for it $marker1_map = $map->addObject($marker1); $map->addObject($marker2); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Marker Basics - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS();