示例#1
0
// 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();
    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;
?>
</title>
示例#3
0
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>
	<link rel="stylesheet" type="text/css" href="_css/style.css">
	<?php 
$map->printHeaderJS();
?>
示例#4
0
<?php

// 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();
$map = new \PHPGoogleMaps\Map();
$map->enableAdsense('pub-9317852351271673', 'small_rectangle');
$map->setCenter('New York, NY');
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Adsense - <?php 
echo PAGE_TITLE;
?>
</title>
	<link rel="stylesheet" type="text/css" href="_css/style.css">
	<?php 
$map->printHeaderJS();
?>
	<?php 
$map->printMapJS();
?>
</head>
<body>
$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">
	<title>Custom Controls - <?php 
echo PAGE_TITLE;
?>
</title>
	<link rel="stylesheet" type="text/css" href="_css/style.css">
	<?php 
$map->printHeaderJS();
?>
示例#6
0
// This is just for my examples
require '_system/config.php';
$relevant_code = array('\\PHPGoogleMaps\\Service\\Geocoder', '\\PHPGoogleMaps\\Service\\GeocodeError', '\\PHPGoogleMaps\\Service\\GeocodeResult', '\\PHPGoogleMaps\\Service\\GeocodeException');
// Autoloader stuff
require '../PHPGoogleMaps/Core/Autoloader.php';
$map_loader = new SplClassLoader('PHPGoogleMaps', '../');
$map_loader->register();
$map = new \PHPGoogleMaps\Map();
// Geocode a location and set the center of the map
// If geocode fails fallback to a different map center
// If no center is set the map will not display
$geocode = \PHPGoogleMaps\Service\Geocoder::geocode('San Diego, CA');
if ($geocode instanceof \PHPGoogleMaps\Service\GeocodeResult) {
    // Set center of map to geocoded location
    $map->setCenter($geocode);
} else {
    $map->setCenter('New York, NY');
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Geocoding - <?php 
echo PAGE_TITLE;
?>
</title>
	<link rel="stylesheet" type="text/css" href="_css/style.css">
	<?php 
    } 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>
	<link rel="stylesheet" type="text/css" href="_css/style.css">
	<?php 
if (isset($map)) {
    ?>
<?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();
?>
示例#9
0
<?php

// This is just for my examples
require '_system/config.php';
$relevant_code = array('\\PHPGoogleMaps\\Service\\DrivingDirections', '\\PHPGoogleMaps\\Service\\WalkingDirections', '\\PHPGoogleMaps\\Service\\BicyclingDirections', '\\PHPGoogleMaps\\Service\\Directions', '\\PHPGoogleMaps\\Service\\DirectionsDecorator');
// 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">