Zend Framework Source Code Snippets

Google Static Maps ViewHelper

Bookmark and Share
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.

Snippet description

is simple google static maps api for zf view helper.
plot on map single marker.

Snippet details

Created:
Nully Nully
6 months ago
Edited:
Nully Nully
6 months ago
Revision Id:
203
Edit Message:
Initial Release
ZF Version
1.10.7
Tags:
view helper google static maps
Comments:
0
Views:
1215
Points:
0 (0 votes)

History

r203

Initial Release

Nully Nully
6 months ago
diff
r202

Initial Release

Nully Nully
6 months ago
diff
r201

Initial Release

Nully Nully
6 months ago