// 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"> <title>Geocoding - <?php
require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); // This is just for my examples require '_system/config.php'; $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>
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(); ?> <?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(); ?>
<?php // This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Core\\CustomControl'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $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">
require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); // This is just for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Event\\EventListener', '\\PHPGoogleMaps\\Event\\DomEventListener', '\\PHPGoogleMaps\\Event\\EventListenerDecorator'); // Create new map $map = new \PHPGoogleMaps\Map(); // Create 2 events $event1 = new \PHPGoogleMaps\Event\EventListener($map, 'idle', 'function(){alert("the map is loaded");}', true); $event2 = new \PHPGoogleMaps\Event\EventListener($map, 'click', 'add_marker'); // Create a DOM event $dom_event1 = new \PHPGoogleMaps\Event\DomEventListener('add_random_marker', 'click', 'add_random_marker'); $map->addObjects(array($event1, $dom_event1)); // Add this event with addObject() so we can use the return value to remove the event $event2_map = $map->addObject($event2); // Set map options $map->setCenter('San Diego, CA'); $map->setZoom(14); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Event Listeners - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <script type="text/javascript">
<?php // This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Layer\\KmlLayer', '\\PHPGoogleMaps\\Layer\\KmlLayerDecorator'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $map = new \PHPGoogleMaps\Map(); $kml = new \PHPGoogleMaps\Layer\KmlLayer('http://local.yahooapis.com/MapsService/rss/trafficData.xml?appid=YahooDemo&city=new+york'); $map->addObject($kml); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>KML Layers - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS(); ?> <?php $map->printMapJS(); ?> </head> <body>
<?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(); $locations = array('New York, NY', 'San Diego, CA', 'Dallas, TX', 'Seattle, WA', 'Miami, FL', 'Atlanta, GA', 'Boise, ID', 'Green Bay, WI', 'Detroit, MI', 'Denver, CO', 'Phoenix, AZ', 'Portland, OR', 'Chicago, IL', 'New Orleans, LA', 'San Francisco, CA', 'Las Vegas, NV'); foreach ($locations as $i => $location) { $marker = \PHPGoogleMaps\Overlay\Marker::createFromLocation($location, array('title' => $location, 'content' => "{$location} marker")); $marker_decorator = $map->addObject($marker); // You have to add the event handler after the marker has been added to a map $click_handler = new \PHPGoogleMaps\Event\EventListener($marker_decorator, 'click', 'function(){alert("You clicked " + ' . $marker_decorator . '.content);}'); $map->addObject($click_handler); } // Diable infowindows so that only the alternate click handler gets triggered $map->disableInfoWindows(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Alternate Click Handlers - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css">
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> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS(); ?>
// Autoloader stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); // 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;
// 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(); ?>
<?php // This is for the examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Overlay\\GroundOverlay', '\\PHPGoogleMaps\\Overlay\\GroundOverlayDecorator'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $map = new \PHPGoogleMaps\Map(); $go = new \PHPGoogleMaps\Overlay\GroundOverlay('http://www.volunteer.blogs.com/winewaves/images/san_diego_postcard.jpg', \PHPGoogleMaps\Service\Geocoder::geocode('San Diego, CA'), \PHPGoogleMaps\Service\Geocoder::geocode('Balboa Park San Diego, CA')); $map->addObject($go); $map->setCenter(\PHPGoogleMaps\Service\Geocoder::geocode('San Diego, CA')); $map->setZoom(14); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Ground Overlays - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS(); ?> <?php $map->printMapJS(); ?>
<?php // This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Overlay\\MapStyle'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $custom_style_json = '[ { featureType: "water", elementType: "all", stylers: [ { hue: "#ff0008" }, { saturation: 71 }, { lightness: -43 }, { gamma: 0.83 } ] },{ featureType: "road", elementType: "all", stylers: [ { saturation: -24 }, { hue: "#1100ff" } ] },{ featureType: "landscape", elementType: "all", stylers: [ { hue: "#11ff00" }, { saturation: 100 }, { lightness: -34 } ] } ]'; $custom_style = new \PHPGoogleMaps\Overlay\MapStyle('Custom', $custom_style_json); $map = new \PHPGoogleMaps\Map(); $map->addObject($custom_style); // You must explicitly set the map types and include the custom style $map->setMapTypes(array('roadmap', 'terrain', $custom_style)); $map->setCenter('San Diego, CA'); $map->setZoom(14); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Custom Map Styles - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <?php $map->printHeaderJS(); ?>
// Autoloader stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); // Create a new map and set some options $map = new \PHPGoogleMaps\Map(); $map->setCenter('USA'); $map->setZoom(3); // If origin and destination are set add directions if (isset($_GET['origin'], $_GET['destination']) && strlen($_GET['origin']) && strlen($_GET['destination'])) { try { $directions = new \PHPGoogleMaps\Service\DrivingDirections($_GET['origin'], $_GET['destination']); if (isset($_GET['waypoint']) && $_GET['waypoint'] != '') { $directions->addWaypoint($_GET['waypoint']); } $map->addObject($directions); } catch (\PHPGoogleMaps\Service\GeocodeException $e) { $error = $e; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Directions - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css">