Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param string|PositionAbstract $southwest Southwest point of the rectangle
  * @param string|PositionAbstract $northeast Northeast point of the rectangle
  * @param array $options Array of rectangle options {@link http://code.google.com/apis/maps/documentation/javascript/reference.html#RectangleOptions}
  * @return Rectangle
  */
 public function __construct($southwest, $northeast, array $options = null)
 {
     if ($southwest instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->southwest = $southwest->getLatLng();
     } else {
         $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($southwest, true);
         if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) {
             $this->southwest = $geocode_result;
         } else {
             throw new \PHPGoogleMaps\Core\GeocodeException($geocode_result);
         }
     }
     if ($northeast instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->northeast = $northeast->getLatLng();
     } else {
         $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($northeast, true);
         if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) {
             $this->northeast = $geocode_result;
         } else {
             throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result);
         }
     }
     if ($options) {
         unset($options['map'], $options['bounds']);
         $this->options = $options;
     }
 }
Exemplo n.º 2
0
 public static function createFromLocation($location, $radius, array $options = null)
 {
     $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($location);
     if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         return new Circle($geocode_result->getLatLng(), $radius, $options);
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * Add a waypoint
  *
  * @param string|PositionAbstract $waypoint The waypoint
  * @param boolean $stopover
  */
 public function addWaypoint($waypoint, $stopover = true)
 {
     if ($waypoint instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->request_options['waypoints'][] = array('location' => $waypoint->getLatLng());
     } else {
         if (($geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($waypoint, true)) instanceof \PHPGoogleMaps\Core\PositionAbstract) {
             $this->request_options['waypoints'][] = array('location' => $geocode_result->getLatLng());
         } else {
             throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Add a path
  * Adds a path to the end of the array of paths
  *
  * @throws GeocodeException
  * @param string|LatLng $location Location to add. This can be a location name
  *                                or a LatLng object.
  * @return void
  */
 public function addPath($location)
 {
     if ($location instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->paths[] = $location->getLatLng();
     } else {
         $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($location, true);
         if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) {
             $this->paths[] = $geocode_result->getLatLng();
         } else {
             throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Geocodes a location
  * 
  * This will return a `LatLng` object if the location is successfully geocoded
  * The object will contain a `latitude`, a `longitude`
  *
  * If an error occurred a `GeocodeError` object will be returned with a `status` property
  * containing the error status returned from google
  *
  * @link http://code.google.com/apis/maps/documentation/geocoding/
  *
  * @param string $location
  * @return LatLng|GeocodeError
  */
 public function geocode($location)
 {
     if ($get_cache = $this->getCache($location)) {
         return $get_cache;
     } else {
         $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($location);
         if ($geocode_result instanceof \PHPGoogleMaps\Service\GeocodeResult) {
             if ($write_cache = $this->writeCache($location, $geocode_result->getLat(), $geocode_result->getLng())) {
                 $geocode_result = new \PHPGoogleMaps\Service\CachedGeocodeResult($geocode_result->getLatLng(), false, true);
             }
         }
         return $geocode_result;
     }
 }
Exemplo n.º 6
0
 /**
  * Factory method to create a marker from a location ( e.g. New York, NY )
  *
  * @param string $location Location of the marker. This will be geocoded for you.
  * @param array $options Array of marker options.
  * @return Marker|False Will return false if geocoding fails.
  * @throws GeocodeException
  */
 public static function createFromLocation($location, array $options = null)
 {
     $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($location);
     if ($geocode_result instanceof \PHPGoogleMaps\Service\GeocodeResult) {
         return self::createFromPosition($geocode_result, $options);
     } else {
         throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result);
     }
 }
Exemplo n.º 7
0
<?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 
Exemplo n.º 8
0
<?php

// 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 
Exemplo n.º 9
0
<?php

// 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">
Exemplo n.º 10
0
 /**
  * Set map center
  *
  * @param string|PositionAbstract $center Location of the center. Can be a
  *                                location or an object that extends PositionAbstract.
  * @return boolean
  */
 public function setCenter($center)
 {
     if ($center instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->center = $center->getLatLng();
         return true;
     }
     $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode((string) $center);
     if ($geocode_result instanceof \PHPGoogleMaps\Service\GeocodeResult) {
         $this->center = $geocode_result->getLatLng();
         return true;
     }
     return false;
 }
Exemplo n.º 11
0
<?php

// This is for my examples
require '_system/config.php';
$relevant_code = array('\\PHPGoogleMaps\\Overlay\\Circle', '\\PHPGoogleMaps\\Overlay\\Rectangle', '\\PHPGoogleMaps\\Overlay\\Shape', '\\PHPGoogleMaps\\Overlay\\ShapeDecorator');
// Autoload stuff
require '../PHPGoogleMaps/Core/Autoloader.php';
$map_loader = new SplClassLoader('PHPGoogleMaps', '../');
$map_loader->register();
$map = new \PHPGoogleMaps\Map();
$circle_options = array('fillColor' => '#00ff00', 'strokeWeight' => 1, 'fillOpacity' => 0.05, 'clickable' => false);
$circle = \PHPGoogleMaps\Overlay\Circle::createFromLocation('San Diego, CA', 1000, $circle_options);
$rectangle_options = array('fillColor' => '#ff0000', 'strokeWeight' => 3, 'fillOpacity' => 0.05);
$rectangle = new \PHPGoogleMaps\Overlay\Rectangle('San Diego, CA', \PHPGoogleMaps\Service\Geocoder::geocode('Balboa Park San Diego, CA'), $rectangle_options);
$map->addObjects(array($circle, $rectangle));
$map->setCenter('San Diego, CA');
$map->setZoom(14);
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Shapes - <?php 
echo PAGE_TITLE;
?>
</title>
	<link rel="stylesheet" type="text/css" href="_css/style.css">
	<?php 
$map->printHeaderJS();
?>
Exemplo n.º 12
0
<?php

// 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();
// If a location is set, geocode it
if (isset($_GET['location']) && strlen($_GET['location'])) {
    $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($_GET['location']);
    if ($geocode_result instanceof \PHPGoogleMaps\Service\GeocodeResult) {
        // If more than one result was found we are going to give the user an option to pick one
        if (count($geocode_result->response->results) > 1) {
            $location = $_GET['location'];
            $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();
Exemplo n.º 13
0
<?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();
?>
Exemplo n.º 14
0
<?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);
$map->centerOnUser(\PHPGoogleMaps\Service\Geocoder::geocode('New Haven, CT'));
$map->setWidth('100%');
$map->setHeight('100%');
$map->enableMobile();
$map->disableAutoEncompass();
$map->setZoom(14);
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Geolocation - <?php 
echo PAGE_TITLE;
?>
</title>
	<link rel="stylesheet" type="text/css" href="_css/style.css">
	<style type="text/css">
	html,body{ height:100%;width:100%;padding:0;margin:0 }
	</style>