Exemple #1
0
 /**
  * Factory method to create a marker from the user's location
  * This uses HTML5's geolocation API
  *
  * @param array options Array of marker options
  * @return Marker
  */
 public static function createFromUserLocation(array $options = null)
 {
     $marker = new Marker(null, $options);
     $marker->enableGeolocation();
     return $marker;
 }
<?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; }
$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;
?>
$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">
<?php

// This is for my examples
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 
 /**
  * Add a marker to the group
  *
  * @param Marker $marker Marker to add to the group
  * @return MarkerGroup
  */
 public function addMarker(\PHPGoogleMaps\Overlay\Marker $marker)
 {
     $marker->addToGroup($this);
     return $this;
 }
Exemple #7
0
 /**
  * Add a marker to the map
  *
  * @param Marker $marker Marker to add
  * @return MarkerDecorator
  * @access protected
  */
 protected function addMarker(\PHPGoogleMaps\Overlay\Marker $marker)
 {
     if (!$marker->getIcon() && $this->default_marker_icon) {
         $marker->setIcon($this->default_marker_icon, $this->default_marker_shadow ?: null);
     }
     return $this->markers[] = new \PHPGoogleMaps\Overlay\MarkerDecorator($marker, count($this->markers), $this->map_id);
 }
<?php

// This is for my examples
require '_system/config.php';
$relevant_code = array('\\PHPGoogleMaps\\Overlay\\Marker', '\\PHPGoogleMaps\\Overlay\\MarkerIcon');
// 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->setIcon(sprintf("http://www.galengrover.com/projects/php-google-maps/examples/_images/blue%s.png", chr($i++ + 65)));
    $map->addObject($marker);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Advanced 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 }
	#map_sidebar *, .infowindow * {padding:0;margin:0;}
	#map_sidebar { float:left;margin-left:20px;overflow:auto;height:500px; border:1px solid #ddd;width:200px;font-size:.8em; }
            $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>
$map_loader->register();
$map = new \PHPGoogleMaps\Map();
// Create a marker
$marker1_options = array('title' => 'Custom marker icon', 'content' => 'This marker uses a custom icon');
$marker1 = \PHPGoogleMaps\Overlay\Marker::createFromLocation('New York, NY', $marker1_options);
// Create a marker icon or the icon and shadow
$icon1 = new \PHPGoogleMaps\Overlay\MarkerIcon('http://www.galengrover.com/projects/php-google-maps/examples/_images/yellow_marker.png');
$shadow1 = new \PHPGoogleMaps\Overlay\MarkerIcon('http://www.galengrover.com/projects/php-google-maps/examples/_images/yellow_marker_shadow.png');
// Set the x anchor point to 11
// y anchor point defaults to image height
$shadow1->setAnchor(11);
// Attach the icon and shadow to the marker
$marker1->setIcon($icon1)->setShadow($shadow1);
// Create another marker
$marker2_options = array('title' => 'Custom marker icon', 'content' => 'This marker uses a custom icon with a sprite to limit http connections');
$marker2 = \PHPGoogleMaps\Overlay\Marker::createFromLocation('New Haven, CT', $marker2_options);
// This one will use a sprite for the icon and shadow
$icon2 = \PHPGoogleMaps\Overlay\MarkerIcon::create('http://www.galengrover.com/projects/php-google-maps/examples/_images/purple_marker_sprite.png', array('height' => 34));
// Height and width default to size of the image
$shadow2_options = array('height' => 24, 'origin_x' => 0, 'origin_y' => 34, 'anchor_x' => 11, 'anchor_y' => 24);
// Create another icon from the same image
$shadow2 = new \PHPGoogleMaps\Overlay\MarkerIcon('http://www.galengrover.com/projects/php-google-maps/examples/_images/purple_marker_sprite.png', $shadow2_options);
// Attach the icon and shadow to the second marker
$marker2->setIcon($icon2)->setShadow($shadow2);
// Add the markers to the map
$map->addObjects(array($marker1, $marker2));
?>

<!DOCTYPE html>
<html lang="en">
<head>
$map_loader = new SplClassLoader('PHPGoogleMaps', '../');
$map_loader->register();
use PHPGoogleMaps\Overlay\Marker, PHPGoogleMaps\Overlay\MarkerGroup;
$map = new \PHPGoogleMaps\Map();
$markers[] = Marker::createFromLocation('New York, NY')->addToGroups(array('North', 'East', 'New York'));
$markers[] = Marker::createFromLocation('Syracuse, NY')->addToGroups(array('North', 'East', 'New York'));
$markers[] = Marker::createFromLocation('San Diego, CA')->addToGroups(array('South', 'West', 'California'));
$markers[] = Marker::createFromLocation('San Francisco, CA')->addToGroups(array('West', 'California'));
$markers[] = Marker::createFromLocation('Houston, TX')->addToGroups(array('South', 'Mid West', 'Texas'));
$markers[] = Marker::createFromLocation('Dallas, TX')->addToGroups(array('South', 'Mid West', 'Texas'));
$markers[] = Marker::createFromLocation('Orlando, FL')->addToGroups(array('South', 'East', 'Florida'));
$markers[] = Marker::createFromLocation('Tampa, FL')->addToGroups(array('South', 'East', 'Florida'));
$markers[] = Marker::createFromLocation('Detroit, MI')->addToGroups(array('North', 'East', 'Michigan'));
$markers[] = Marker::createFromLocation('Ann Arbor, MI')->addToGroups(array('North', 'East', 'Michigan'));
$markers[] = Marker::createFromLocation('Seattle, WA')->addToGroups(array('North', 'West'));
$markers[] = Marker::createFromLocation('Denver, CO')->addToGroups(array('Mid West'));
// It is also possible to add groups this way
// Pass an array of markers to `addMarkers()`
// This just calls `addToGroup()` on the marker
//$group_ca = MarkerGroup::create( 'California' )->addMarkers( array() );
//$group_tx = MarkerGroup::create( 'Texas' )->addMarkers( array() );
//$group_fl = MarkerGroup::create( 'Florida' )->addMarkers( array();
//$group_mi = MarkerGroup::create( 'Michigan' )->addMarkers( array() );
// Groups aren't added to map
// The markers associated with them are
$map->addObjects($markers);
?>

<!DOCTYPE html>
<html lang="en">
<head>
Exemple #12
0
// 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>
Exemple #13
0
$map_loader->register();
$map = new \PHPGoogleMaps\Map();
$map2 = new \PHPGoogleMaps\Map(array('map_id' => 'map2'));
$map3 = new \PHPGoogleMaps\Map(array('map_id' => 'map3'));
$locations = array('New York, NY', 'San Diego, CA', 'Miami, FL', 'Chicago, IL', 'Las Vegas, NV', 'Austin, TX', 'Portland, OR', 'Washington, D.C.');
$marker_sizes = array('tiny', 'mid', 'small', 'normal');
foreach ($locations as $i => $location) {
    $marker = \PHPGoogleMaps\Overlay\Marker::createFromLocation($location, array('static' => array('label' => substr($location, 0, 1), 'color' => sprintf('0x%s%s%s', dechex(str_pad(mt_rand(0, 255), 2, '0')), dechex(str_pad(mt_rand(0, 255), 2, '0')), dechex(str_pad(mt_rand(0, 255), 2, '0'))), 'size' => $marker_sizes[array_rand($marker_sizes)])));
    $map->addObject($marker);
    $map2->addObject($marker);
}
$marker = \PHPGoogleMaps\Overlay\Marker::createFromLocation('New Haven, CT');
$icon = new \PHPGoogleMaps\Overlay\MarkerIcon('http://galengrover.com/projects/php-google-maps/examples/_images/bullseye_marker.png');
$marker->setStaticVar('flat', true);
$marker->setIcon($icon);
$marker2 = \PHPGoogleMaps\Overlay\Marker::createFromLocation('New York, NY');
$icon2 = new \PHPGoogleMaps\Overlay\MarkerIcon('http://galengrover.com/projects/php-google-maps/examples/_images/yellow_marker.png');
$marker2->setIcon($icon2);
$map3->addObjects(array($marker, $marker2));
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Static Maps - <?php 
echo PAGE_TITLE;
?>
</title>
	<link rel="stylesheet" type="text/css" href="_css/style.css">
	<?php 
Exemple #14
0
// This is just for my examples
require '_system/config.php';
// 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">
<?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();