// 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"> <title>Geocoding - <?php echo PAGE_TITLE; ?>
require '_system/config.php'; // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $map = new \PHPGoogleMaps\Map(); // $marker = \PHPGoogleMaps\Overlay\Marker::createFromUserLocation(array('geolocation_high_accuracy' => true, 'geolocation_timeout' => 10000)); $map->addObject($marker); // If you want to set geolocation options you must call enableGeolocation() explicitly // Otherwise it will be called for you when you use geolocation functions $map->enableGeolocation(5000, true); $map->centerOnUser(\PHPGoogleMaps\Service\Geocoder::geocode('New York, NY')); $map->setWidth('500px'); $map->setHeight('500px'); $map->setZoom(16); // Set the callbacks $map->setGeolocationFailCallback('geofail'); $map->setGeolocationSuccessCallback('geosuccess'); // Set the loading content. This will display while the browser geolocates the user. $map->setLoadingContent('<div style="background:#eee;height:300px;padding: 200px 0 0 0;text-align:center;"><img src="_images/loading.gif" style="display:block; margin: auto;"><p>Locating you...</p></div>'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Geolocation - <?php echo PAGE_TITLE; ?> </title>
<?php // This is just for my examples require '_system/config.php'; $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>
// This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Overlay\\Polyline', '\\PHPGoogleMaps\\Overlay\\Poly', '\\PHPGoogleMaps\\Overlay\\PolyDecorator'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $map = new \PHPGoogleMaps\Map(); use PHPGoogleMaps\Service\Geocoder; $polyline_paths = array(Geocoder::geocode('San Diego, CA'), Geocoder::geocode('Austin, TX'), Geocoder::geocode('New Haven, CT'), Geocoder::geocode('Seattle, WA')); $polyline_options = array('strokeColor' => '#0000ff', 'clickable' => false); $polyline = new \PHPGoogleMaps\Overlay\Polyline($polyline_paths, $polyline_options); $polyline->addPath('San Francisco, CA'); $map->disableAutoEncompass(); $map->setCenter('Austin, TX'); $map->setZoom(3); $polyline_map = $map->addObject($polyline); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Polylines - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS(); ?>
$relevant_code = array('\\PHPGoogleMaps\\Layer\\FusionTable', '\\PHPGoogleMaps\\Layer\\FusionTableDecorator'); // Create a map $map = new \PHPGoogleMaps\Map(); // Create a fusion table for CT $ft_ct_options = array('query' => 'SELECT location FROM 232192 WHERE state_province_abbrev="CT"'); $ft_ct = new \PHPGoogleMaps\Layer\FusionTable(232192, $ft_ct_options); // Create a fusion table for RI $ft_ri_options = array('query' => 'SELECT location FROM 232192 WHERE state_province_abbrev="RI"'); $ft_ri = new \PHPGoogleMaps\Layer\FusionTable(232192, $ft_ri_options); // Add the CT fusion table to the map and get the decorator for later use $ft_ct_map = $map->addObject($ft_ct); // Add the RI fusion table to the map $map->addObject($ft_ri); // Set map options $map->setCenter('Connecticut'); $map->setZoom(7); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Fusion Tables - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS(); ?> <?php
$map = new \PHPGoogleMaps\Map(); $custom_control_outer_options = array('style.backgroundColor' => 'white', 'style.borderStyle' => 'solid', 'style.borderWidth' => '2px', 'style.cursor' => 'pointer', 'style.textAlign' => 'center', 'title' => 'Click to say hi', 'style.margin' => '5px'); $custom_control_inner_options = array('style.fontFamily' => 'Arial,sans-serif', 'style.fontSize' => '12px', 'style.paddingLeft' => '4px', 'style.paddingRight' => '4px', 'innerHTML' => '<b>Custom1</b>'); // Create a control and add a listener $custom_control = new \PHPGoogleMaps\Core\CustomControl($custom_control_outer_options, $custom_control_inner_options, 'BOTTOM_LEFT'); $custom_control->addListener('click', 'function(){ alert("You clicked Custom1"); }'); $map->addObject($custom_control); // Create a control and event, attaching the event to the control // This has the added benefit of being able to remove the event later using $event $custom_control_inner_options['innerHTML'] = '<b>Custom2</b>'; $custom_control2 = new \PHPGoogleMaps\Core\CustomControl($custom_control_outer_options, $custom_control_inner_options, 'BOTTOM_LEFT'); $custom_control2_map = $map->addObject($custom_control2); $event = new \PHPGoogleMaps\Event\DomEventListener($custom_control2_map, 'click', 'function(){ alert("You clicked Custom2"); }'); $map->addObject($event); $map->setCenter('San Diego, CA'); $map->setZoom(14); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Custom Controls - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS(); ?> <?php
<?php // This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Layer\\PanoramioLayer', '\\PHPGoogleMaps\\Layer\\PanoramioLayerDecorator'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $map = new \PHPGoogleMaps\Map(); $panoramio = new \PHPGoogleMaps\Layer\PanoramioLayer(); $panoramio->setTag('beach'); //$panoramio->setUserID( 4106947 ); $map->addObject($panoramio); $map->setCenter('San Diego, CA'); $map->setZoom(10); $map->disableAutoEncompass(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Panoramio - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS(); ?>
// Create a new map $map = new \PHPGoogleMaps\Map(); // Create some circle options $circle_options = array('fillColor' => '#00ff00', 'strokeWeight' => 1, 'fillOpacity' => 0.05, 'clickable' => false); // Create a circle with radius of 100m $circle = \PHPGoogleMaps\Overlay\Circle::createFromLocation('San Diego, CA', 100, $circle_options); // Create some marker options $marker_options = array('title' => 'San Diego, CA', 'content' => '<p><strong>San Diego, CA</strong></p>', 'draggable' => true); // Create a marker $marker = \PHPGoogleMaps\Overlay\Marker::createFromLocation('San Diego, CA', $marker_options); // Add the circle and marker to the map $circle_map = $map->addObject($circle); $marker_map = $map->addObject($marker); // Set map options $map->setCenter('San Diego, CA'); $map->setZoom(15); $map->disableAutoEncompass(); // bind the center of the circle to the position of the marker $map->bind($circle_map, 'center', $marker_map, 'position'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Binding Objects - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php