Exemple #1
0
 /**
  * Function executed when the service is called
  *
  * @param Request
  * @return Response
  * */
 public function _main(Request $request)
 {
     // do not allow blank searches
     if (empty($request->query)) {
         $response = new Response();
         $response->setResponseSubject("De donde sacamos el mapa?");
         $response->createFromText("Usted no ha insertado ninguna direcci&oacute;n, coordenadas o lugar famoso a buscar. Inserte el texto en el asunto del email, justo despu&eacute;s de la palabra MAPA.<br/><br/>Por ejemplo: Asunto: <b>MAPA capitolio, cuba</b>");
         return $response;
     }
     // include google maps library
     require_once "{$this->pathToService}/lib/GoogleStaticMap.php";
     require_once "{$this->pathToService}/lib/GoogleStaticMapFeature.php";
     require_once "{$this->pathToService}/lib/GoogleStaticMapFeatureStyling.php";
     require_once "{$this->pathToService}/lib/GoogleStaticMapMarker.php";
     require_once "{$this->pathToService}/lib/GoogleStaticMapPath.php";
     require_once "{$this->pathToService}/lib/GoogleStaticMapPathPoint.php";
     // get and clean the argument
     $argument = $request->query;
     $argument = str_replace("\n", " ", $argument);
     $argument = str_replace("\r", "", $argument);
     $argument = trim(strtolower($argument));
     // detecting type
     $type = 'hibrido';
     $internalType = "hybrid";
     if (stripos($argument, 'fisico') !== false) {
         $type = 'fisico';
         $internalType = "satellite";
     } elseif (stripos($argument, 'politico') !== false) {
         $type = 'politico';
         $internalType = "roadmap";
     } elseif (stripos($argument, 'terreno') !== false) {
         $type = 'terreno';
         $internalType = "terrain";
     }
     // remove the type from the query to display on the template
     $argument = str_ireplace($type, '', $argument);
     // detecting zoom
     $zoom = null;
     for ($i = 22; $i >= 1; $i--) {
         if (stripos($argument, $i . 'x') !== false) {
             $zoom = $i;
             $argument = str_ireplace("{$i}x", '', $argument);
         }
     }
     // remove bad starting arguments
     if (substr($argument, 0, 3) == 'de ') {
         $argument = substr($argument, 3);
     }
     if (substr($argument, 0, 4) == 'del ') {
         $argument = substr($argument, 4);
     }
     // create the map
     $oStaticMap = new GoogleStaticMap();
     $oStaticMap->setScale(1);
     $oStaticMap->setHeight(400);
     $oStaticMap->setWidth(400);
     $oStaticMap->setLanguage("es");
     $oStaticMap->setHttps(true);
     $oStaticMap->setMapType($internalType);
     if (!is_null($zoom)) {
         $oStaticMap->setZoom($zoom);
     }
     $oStaticMap->setCenter($argument);
     // get path to the www folder
     $di = \Phalcon\DI\FactoryDefault::getDefault();
     $wwwroot = $di->get('path')['root'];
     // save the image as a temp file
     $mapImagePath = "{$wwwroot}/temp/" . $this->utils->generateRandomHash() . ".jpg";
     $content = file_get_contents($oStaticMap);
     file_put_contents($mapImagePath, $content);
     // optimize the image
     $this->utils->optimizeImage($mapImagePath);
     // create the response variables
     $responseContent = array("type" => $type, "request" => $argument, "zoom" => $zoom, "image" => $mapImagePath);
     // create the response
     $response = new Response();
     $response->setResponseSubject("Mapa para " . $request->query);
     $response->createFromTemplate("basic.tpl", $responseContent, array($mapImagePath));
     return $response;
 }
<?php

/*
 * Generates a 600x600 pixel google map, centered over 3 path points, 1 defined
 * using coordinates, the other 2 using a string. The path is filled, as there
 * are more than 2 with a transparent yellow.
 */
include '../googlestaticmap.php';
include '../googlestaticmapfeature.php';
include '../googlestaticmapfeaturestyling.php';
include '../googlestaticmapmarker.php';
include '../googlestaticmappath.php';
include '../googlestaticmappathpoint.php';
$oStaticMap = new GoogleStaticMap();
$oStaticMap->setHeight(600)->setWidth(600)->setMapType('hybrid')->setFormat('png8');
//Create Path Object and set styling
$oPath = new GoogleStaticMapPath();
$oPath->setColor('0x00000000')->setWeight(5)->setFillColor('0xFFFF0033');
//Create Point
$oPathPoint = new GoogleStaticMapPathPoint();
$oPathPoint->setLatitude(51.855376)->setLongitude(-0.576904);
$oPath->setPoint($oPathPoint);
//Create Another Path Point
$oPathPoint2 = new GoogleStaticMapPathPoint();
$oPathPoint2->setLocation('Wembley, UK');
$oPath->setPoint($oPathPoint2);
//Create Another Path Point
$oPathPoint3 = new GoogleStaticMapPathPoint();
$oPathPoint3->setLocation('Barnet, UK');
$oPath->setPoint($oPathPoint3);
//Add Points to Map
<?php

/*
 * Generates a 300x232 pixel google map, centered over london, using an HTTPS
 * connection, 2 markers (Med & Large) with labels.
 */
include '../googlestaticmap.php';
include '../googlestaticmapfeature.php';
include '../googlestaticmapfeaturestyling.php';
include '../googlestaticmapmarker.php';
include '../googlestaticmappath.php';
include '../googlestaticmappathpoint.php';
$oStaticMap = new GoogleStaticMap();
$oStaticMap->setCenter('London,UK')->setHeight(300)->setWidth(300)->setZoom(8)->setMapType('hybrid')->setFormat('png');
$oStaticMap->setMarker(array('color' => 'blue', 'size' => 'mid', 'longitude' => -0.062004, 'latitude' => 51.462564, 'label' => 'C'));
$oMarker = new GoogleStaticMapMarker();
$oMarker->setColor('red')->setSize('large')->setLongitude(-0.576904)->setLatitude(51.855376)->setLabel('B');
$oStaticMap->setMarker($oMarker);
echo '<img src="' . $oStaticMap . '" height="' . $oStaticMap->getHeight() . '" width="' . $oStaticMap->getWidth() . '" />';
<?php

/*
 * Generates a 300x232 pixel google map, centered over london, 
 * with light green features.
 */
include '../googlestaticmap.php';
include '../googlestaticmapfeature.php';
include '../googlestaticmapfeaturestyling.php';
include '../googlestaticmapmarker.php';
include '../googlestaticmappath.php';
include '../googlestaticmappathpoint.php';
$oStaticMap = new GoogleStaticMap();
$oStaticMap->setCenter("London,UK")->setHeight(300)->setWidth(232)->setZoom(8)->setFormat("jpg")->setFeatureStyling(array("feature" => "all", "element" => "all", "style" => array("hue" => "#006400", "lightness" => 50)));
echo '<img src="' . $oStaticMap . '" height="' . $oStaticMap->getHeight() . '" width="' . $oStaticMap->getWidth() . '" />';
<?php

/*
 * Generates a 300x232 pixel google map, centered over london, using an HTTPS
 * connection
 */
include '../googlestaticmap.php';
include '../googlestaticmapfeature.php';
include '../googlestaticmapfeaturestyling.php';
include '../googlestaticmapmarker.php';
include '../googlestaticmappath.php';
include '../googlestaticmappathpoint.php';
$oStaticMap = new GoogleStaticMap();
$oStaticMap->setCenter("London,UK")->setHeight(300)->setWidth(232)->setZoom(8)->setHttps(true);
echo '<img src="' . $oStaticMap . '" height="' . $oStaticMap->getHeight() . '" width="' . $oStaticMap->getWidth() . '" />';