Google Static Maps ViewHelper
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 2526 27 28 29 3031 32 33 34 3536 37 38 39 4041 42 43 44 | /* Usage */ <img src="<?= $this->staticMap($lat, $lng, array( "size" => "300x300", "maptype" => My_View_Helper_StaticMap::MAPTYPE_HYBRID, "zoom" => 18, "sensor" => false, )); ?>" alt="Static map !" /> <?php /* StaicMap ViewHelper */ class My_View_Helper_StaticMap extends Zend_View_Helper_Abstract { protected $_baseMapUrl = "http://maps.google.com/maps/api/staticmap"; // Google Maps Static API base url. const MAPTYPE_ROADMAP ="roadmap"; const MAPTYPE_SATELLITE ="satellite"; const MAPTYPE_TERRAIN = "terrain"; const MAPTYPE_HYBRID = "hybrid"; public function staticMap($lat, $lng, $params = array()) { $defaults = array( "zoom" => 14, "maptype" => self::MAPTYPE_ROADMAP, "size" => "128x128", "sensor" => false, ); $params = array_merge($defaults, $params); $params["center"] = sprintf( '%1$s,%2$s', $lat, $lng ); $params["markers"] = sprintf( 'color:yellow|%1$s,%2$s', $lat, $lng ); $uri = $this->_buildMapUri($params); return $uri; } protected function _buildMapUri($params) { $uri = Zend_Uri_Http::fromString($this->_baseMapUrl); $uri->setQuery($params); return $uri->__toString(); } } |
Comments
You must login before commenting on a snippet. If you do not have an account, please register.