├── Google ├── Maps.php └── Maps │ ├── Bounds.php │ ├── Clusterer.php │ ├── Clusterer │ ├── Distance.php │ └── None.php │ ├── Control.php │ ├── Control │ ├── Pan.php │ └── Zoom.php │ ├── Coordinate.php │ ├── Infowindow.php │ ├── Location.php │ ├── Marker.php │ ├── Marker │ └── Cluster.php │ ├── Math.php │ ├── Mercator.php │ ├── Overload.php │ ├── Path.php │ ├── Point.php │ └── Static.php ├── README ├── cities.kml ├── cluster.html ├── controls.html ├── css ├── controls.css └── infowindow.css ├── kml.html └── tests ├── 01_lattoy.phpt ├── 02_lontox.phpt ├── 03_xtolon.phpt ├── 04_ytolat.phpt ├── 05_bounds.phpt ├── 06_point.phpt ├── 07_coordinate.phpt ├── 08_maps_factory.phpt ├── 09_bounds_contains.phpt ├── 10_marker.phpt ├── 11_maps_setcenter.phpt └── skipif.php /Google/Maps.php: -------------------------------------------------------------------------------- 1 | toCoordinate(); 43 | } else { 44 | $coordinate_list[] = $location; 45 | } 46 | } 47 | 48 | $coordinate = array_pop($coordinate_list); 49 | $this->setMinLon($coordinate->getLon()); 50 | $this->setMinLat($coordinate->getLat()); 51 | $this->setMaxLon($coordinate->getLon()); 52 | $this->setMaxLat($coordinate->getLat()); 53 | 54 | foreach ($coordinate_list as $coordinate) { 55 | if ($coordinate->getLon() < $this->getMinLon()) { 56 | $this->setMinLon($coordinate->getLon()); 57 | } 58 | if ($coordinate->getLon() > $this->getMaxLon()) { 59 | $this->setMaxLon($coordinate->getLon()); 60 | } 61 | if ($coordinate->getLat() < $this->getMinLat()) { 62 | $this->setMinLat($coordinate->getLat()); 63 | } 64 | if ($coordinate->getLat() > $this->getMaxLat()) { 65 | $this->setMaxLat($coordinate->getLat()); 66 | } 67 | } 68 | 69 | } 70 | 71 | /** 72 | * Return north-west corner of bounds. 73 | * 74 | * @return mixed Google_Maps_Coordinate or Google_Maps_Point 75 | */ 76 | 77 | public function getNorthWest($type='') { 78 | $lat = $this->getMaxLat(); 79 | $lon = $this->getMinLon(); 80 | $retval = new Google_Maps_Coordinate($lat, $lon); 81 | if ('point' == $type) { 82 | $retval = $retval->toPoint(); 83 | } 84 | return $retval; 85 | } 86 | 87 | /** 88 | * Return north-east corner of bounds. 89 | * 90 | * @return mixed Google_Maps_Coordinate or Google_Maps_Point 91 | */ 92 | 93 | public function getNorthEast($type='') { 94 | $lat = $this->getMaxLat(); 95 | $lon = $this->getMaxLon(); 96 | $retval = new Google_Maps_Coordinate($lat, $lon); 97 | if ('point' == $type) { 98 | $retval = $retval->toPoint(); 99 | } 100 | return $retval; 101 | } 102 | 103 | /** 104 | * Return souts-east corner of bounds. 105 | * 106 | * @return mixed Google_Maps_Coordinate or Google_Maps_Point 107 | */ 108 | 109 | public function getSouthEast($type='') { 110 | $lat = $this->getMinLat(); 111 | $lon = $this->getMaxLon(); 112 | $retval = new Google_Maps_Coordinate($lat, $lon); 113 | if ('point' == $type) { 114 | $retval = $retval->toPoint(); 115 | } 116 | return $retval; 117 | } 118 | 119 | /** 120 | * Return south-west corner of bounds. 121 | * 122 | * @return mixed Google_Maps_Coordinate or Google_Maps_Point 123 | */ 124 | 125 | public function getSouthWest($type='') { 126 | $lat = $this->getMinLat(); 127 | $lon = $this->getMinLon(); 128 | $retval = new Google_Maps_Coordinate($lat, $lon); 129 | if ('point' == $type) { 130 | $retval = $retval->toPoint(); 131 | } 132 | return $retval; 133 | } 134 | 135 | /** 136 | * Check if given coordinate, point or bounds is inside bounds 137 | * 138 | * @return boolean 139 | */ 140 | 141 | public function contains($bounds_or_location) { 142 | if ($bounds_or_location instanceof Google_Maps_Bounds) { 143 | $retval = $this->containsBounds($bounds_or_location); 144 | } else { 145 | $retval = $this->containsLocation($bounds_or_location); 146 | } 147 | return $retval; 148 | } 149 | 150 | /** 151 | * Check if given coordinate or point is inside bounds 152 | * 153 | * @return boolean 154 | */ 155 | 156 | public function containsLocation(Google_Maps_Location $location) { 157 | $retval = false; 158 | $coordinate = $location->toCoordinate(); 159 | if ($coordinate->getLon() < $this->getMaxLon() && $coordinate->getLon() > $this->getMinLon() && 160 | $coordinate->getLat() < $this->getMaxLat() && $coordinate->getLat() > $this->getMinLat()) { 161 | $retval = true; 162 | } 163 | return $retval; 164 | } 165 | 166 | /** 167 | * Check if given bounds is inside bounds 168 | * 169 | * @return boolean 170 | */ 171 | 172 | public function containsBounds(Google_Maps_Bounds $bounds) { 173 | $retval = false; 174 | if ($this->containsLocation($bounds->getNorthEast()) && 175 | $this->containsLocation($bounds->getSouthWest())) { 176 | $retval = true; 177 | } 178 | return $retval; 179 | } 180 | 181 | /** 182 | * Returns array of path objects which can be used for drawing 183 | * borders of current bounds object into the static map. Can be 184 | * used for debugging. 185 | * 186 | * @return array of Google_Maps_Path 187 | */ 188 | 189 | public function getPath() { 190 | return array(new Google_Maps_Path($this->getNorthWest()), 191 | new Google_Maps_Path($this->getNorthEast()), 192 | new Google_Maps_Path($this->getSouthEast()), 193 | new Google_Maps_Path($this->getSouthWest()), 194 | new Google_Maps_Path($this->getNorthWest())); 195 | } 196 | 197 | } -------------------------------------------------------------------------------- /Google/Maps/Clusterer.php: -------------------------------------------------------------------------------- 1 | getDistance(); 30 | $unit = $this->getUnit(); 31 | while (count($markers)) { 32 | $marker = array_pop($markers); 33 | $cluster = new Google_Maps_Marker_Cluster(); 34 | foreach ($markers as $key => $target) { 35 | if (($distance > $marker->distanceTo($target, $unit, $map))) { 36 | unset($markers[$key]); 37 | $amount = $cluster->addMarker($target); 38 | /* Marker can display max number 9, so break out of */ 39 | /* the loop when we reach it. One is added outside of the loop. */ 40 | if (8 == $amount) { 41 | break 1; 42 | } 43 | 44 | } 45 | } 46 | 47 | if (count($cluster->getMarkers()) > 0) { 48 | $sizes = $this->getMarkerSizes(); 49 | $count = $cluster->addMarker($marker); 50 | $cluster->setCharacter($count); 51 | $cluster->setColor('blue'); 52 | $cluster->setSize($sizes[$count - 1]); 53 | $clustered[] = $cluster; 54 | } else { 55 | $clustered[] = $marker; 56 | }; 57 | } 58 | return $clustered; 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /Google/Maps/Clusterer/None.php: -------------------------------------------------------------------------------- 1 | panNorth(60); 40 | $pan_north = sprintf('%s', 41 | $_SERVER['PHP_SELF'] . '?' . $map->toQueryString(), $this->getPanNorthImage(), $this->getPanNorthId(), $this->getPanNorthAlt()); 42 | $map->panSouth(60); 43 | 44 | $map->panWest(100); 45 | $pan_west = sprintf('%s', 46 | $_SERVER['PHP_SELF'] . '?' . $map->toQueryString(), $this->getPanWestImage(), $this->getPanWestId(), $this->getPanWestAlt()); 47 | $map->panEast(100); 48 | 49 | $map->panEast(100); 50 | $pan_east = sprintf('%s', 51 | $_SERVER['PHP_SELF'] . '?' . $map->toQueryString(), $this->getPanEastImage(), $this->getPanEastId(), $this->getPanEastAlt()); 52 | $map->panWest(100); 53 | 54 | $map->panSouth(60); 55 | $pan_south = sprintf('%s', 56 | $_SERVER['PHP_SELF'] . '?' . $map->toQueryString(), $this->getPanSouthImage(), $this->getPanSouthId(), $this->getPanSouthAlt()); 57 | $map->panNorth(60); 58 | 59 | return $pan_north . $pan_west . $pan_east . $pan_south; 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /Google/Maps/Control/Zoom.php: -------------------------------------------------------------------------------- 1 | getZoom(); 32 | $map->zoomIn(); 33 | $zoom_in = sprintf('%s', 34 | $_SERVER['PHP_SELF'] . '?' . $map->toQueryString(), $this->getZoomInImage(), $this->getZoomInId(), $this->getZoomInAlt()); 35 | $map->setZoom($original); 36 | $map->zoomOut(); 37 | $zoom_out = sprintf('%s', 38 | $_SERVER['PHP_SELF'] . '?' . $map->toQueryString(), $this->getZoomOutImage(), $this->getZoomOutId(), $this->getZoomOutAlt()); 39 | $map->setZoom($original); 40 | return $zoom_in . $zoom_out; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /Google/Maps/Coordinate.php: -------------------------------------------------------------------------------- 1 | setLat($lat); 36 | $this->setLon($lon); 37 | } 38 | 39 | /** 40 | * Return coordinate as point in Google Maps. 41 | * 42 | * @return object Google_Maps_Point 43 | */ 44 | public function toPoint() { 45 | $lat = $this->getLat(); 46 | $lon = $this->getLon(); 47 | $x = Google_Maps_Mercator::LonToX($lon); 48 | $y = Google_Maps_Mercator::LatToY($lat); 49 | return new Google_Maps_Point($x, $y); 50 | } 51 | 52 | public function getLat($format='%01.8f') { 53 | return sprintf($format, $this->lat); 54 | } 55 | 56 | public function getLon($format='%01.8f') { 57 | return sprintf($format, $this->lon); 58 | } 59 | 60 | /** 61 | * Return coordinate as coordinate. This method exists only 62 | * provide unified API between coordinate and point objects. 63 | * 64 | * @return object Google_Maps_Coordinate 65 | */ 66 | public function toCoordinate() { 67 | return $this; 68 | } 69 | 70 | public function __toString() { 71 | return $this->getLat() . ',' . $this->getLon(); 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /Google/Maps/Infowindow.php: -------------------------------------------------------------------------------- 1 | 27 |
28 |
29 | 30 |
31 |
32 | 33 |
34 |
35 | 36 |
37 |
38 | 39 |
40 |
41 | 42 |
43 |
44 |
45 |
46 |

47 | 48 |

49 |
50 | %s 51 |
52 |
53 | 54 | '; 55 | 56 | /** 57 | * Class constructor. 58 | * 59 | * @param string $content 60 | * @param array $params Optional parameters (unused for now) 61 | * @return object 62 | */ 63 | public function __construct($content, $params = array()) { 64 | $this->setContent($content); 65 | $this->setProperties($params); 66 | } 67 | 68 | /** 69 | * Show infowindow. 70 | * 71 | * @return boolean 72 | */ 73 | public function show() { 74 | $this->setDisplay('block'); 75 | } 76 | 77 | /** 78 | * Hide infowindow. 79 | * 80 | * @return boolean 81 | */ 82 | public function hide() { 83 | $this->setDisplay('none'); 84 | } 85 | 86 | /** 87 | * Is infowindow currently visible? 88 | * 89 | * @return boolean 90 | */ 91 | public function isVisible() { 92 | return $this->getDisplay() == 'block' ? true : false; 93 | } 94 | 95 | public function getCloseUrl(Google_Maps_Static $map) { 96 | return preg_replace('/infowindow=.*&/', 'infowindow=&', $map->toUrl('?', false)); 97 | } 98 | 99 | public function toHtml(Google_Maps_Static $map) { 100 | $template = $this->getTemplate(); 101 | $location = $this->getMarker(); 102 | return sprintf($template, $location->getId(), 103 | $location->getContainerX($map) - 160, 104 | $location->getContainerY($map) - 235, 105 | $this->getDisplay(), 106 | $this->getCloseUrl($map), 107 | $this->getContent()); 108 | } 109 | 110 | public function __toString() { 111 | } 112 | 113 | } -------------------------------------------------------------------------------- /Google/Maps/Location.php: -------------------------------------------------------------------------------- 1 | getZoom(); 43 | $target_x = $this->toPoint()->getX(); 44 | $center_x = $map->getCenter()->toPoint()->getX(); 45 | $delta_x = ($target_x - $center_x) >> (21 - $zoom); 46 | 47 | $center_offset_x = round($map->getWidth() / 2); 48 | 49 | return $center_offset_x + $delta_x; 50 | } 51 | 52 | /** 53 | * Return y coordinate inside current map image 54 | * 55 | * @return integer 56 | */ 57 | public function getContainerY(Google_Maps_Static $map) { 58 | $zoom = $map->getZoom(); 59 | $target_y = $this->toPoint()->getY(); 60 | $center_y = $map->getCenter()->toPoint()->getY(); 61 | $delta_y = ($target_y - $center_y) >> (21 - $zoom); 62 | 63 | $center_offset_y = round($map->getHeight() / 2); 64 | 65 | return $center_offset_y + $delta_y; 66 | } 67 | 68 | public function distanceTo(Google_Maps_Location $location, $unit='km', Google_Maps_Static $map=null) { 69 | if ('pixel' == $unit) { 70 | $zoom = $map->getZoom(); 71 | $x1 = $this->toPoint()->getX(); 72 | $x2 = $location->toPoint()->getX(); 73 | $y1 = $this->toPoint()->getY(); 74 | $y2 = $location->toPoint()->getY(); 75 | 76 | $distance = sqrt(pow(($x1-$x2),2) + pow(($y1-$y2),2)); 77 | 78 | if ($map instanceof Google_Maps_Static) { 79 | $distance = $distance >> (21 - $zoom); 80 | } 81 | } 82 | 83 | return $distance; 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /Google/Maps/Marker.php: -------------------------------------------------------------------------------- 1 | setCoordinate($location); 43 | $this->setProperties($params); 44 | $this->setId('marker_' . self::$counter++); 45 | } 46 | 47 | /** 48 | * Return imagemap area. Used for clickable markers in static map. 49 | * 50 | * @return string 51 | */ 52 | public function toArea(Google_Maps_Static $map) { 53 | $marker_x = $this->getContainerX($map); 54 | $marker_y = $this->getContainerY($map) - 20; 55 | $marker_id = $this->getId(); 56 | 57 | $string = 'infowindow=' . $marker_id . '&'; 58 | $url = preg_replace('/infowindow=.*&/', $string, $map->toQueryString()); 59 | 60 | return sprintf('', 61 | $marker_x, $marker_y, $url, $marker_id); 62 | } 63 | 64 | /** 65 | * Return marker as coordinate in Google Maps. 66 | * 67 | * @return object Google_Maps_Coordinate 68 | */ 69 | public function toCoordinate() { 70 | return $this->getCoordinate(); 71 | } 72 | 73 | /** 74 | * Return marker as pixel point in Google Maps. 75 | * 76 | * @return object Google_Maps_Point 77 | */ 78 | public function toPoint() { 79 | return $this->getCoordinate()->toPoint(); 80 | } 81 | 82 | /** 83 | * Return latitude of marker coordinate. 84 | * 85 | * @return float Latitude 86 | */ 87 | public function getLat() { 88 | return $this->getCoordinate()->getLat(); 89 | } 90 | 91 | /** 92 | * Return longitude of path coordinate. 93 | * 94 | * @return float Longitude 95 | */ 96 | public function getLon() { 97 | return $this->getCoordinate()->getLon(); 98 | } 99 | 100 | /** 101 | * Return color of marker. 102 | * 103 | * @return string color 104 | */ 105 | public function getColor() { 106 | $retval = $this->color; 107 | if (!trim($this->character)) { 108 | if (trim($retval)) $retval .= '|'; 109 | } 110 | return (trim($retval)) ? 'color:'.$retval : ''; 111 | } 112 | 113 | public function getCharacter() { 114 | $retval = $this->character; 115 | $firstchar = ''; 116 | if (trim($this->color)) { 117 | if (trim($retval)) $firstchar = '|'; 118 | } 119 | return (trim($retval)) ? $firstchar.'label:'.$retval.'|' : ''; 120 | } 121 | 122 | public function __toString() { 123 | $retval = sprintf($this->getFormat(), $this->getColor(), $this->getCharacter(), $this->getLat(), $this->getLon(), 124 | $this->getSize()); 125 | return preg_replace('/,$/', '', $retval); 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /Google/Maps/Marker/Cluster.php: -------------------------------------------------------------------------------- 1 | setMarkers($markers); 35 | $this->setCharacter($count); 36 | $this->setProperties($params); 37 | $this->setId('cluster_' . self::$counter++); 38 | } 39 | 40 | /** 41 | * Set markers which create this cluster. 42 | * 43 | * @param array $markers Google_Maps_Marker 44 | * @return integer number of markers in this cluster. 45 | */ 46 | public function setMarkers($markers = array()) { 47 | $this->markers = $markers; 48 | return count($markers); 49 | } 50 | 51 | /** 52 | * Add marker to cluster. 53 | * 54 | * @param object Google_Maps_Marker 55 | * @return integer Total number of markers in map. 56 | */ 57 | public function addMarker($marker) { 58 | $this->markers[] = $marker; 59 | return count($this->getMarkers()); 60 | } 61 | 62 | /** 63 | * Remove marker from cluster. 64 | * 65 | * @param object Google_Maps_Marker 66 | * @return integer Total number of markers in map. 67 | */ 68 | public function removeMarker($marker) { 69 | $markers = array(); 70 | foreach ($this->getMarkers() as $target) { 71 | if ($marker != $target) { 72 | $markers[] = $target; 73 | } 74 | } 75 | $this->setMarkers($markers); 76 | return count($markers); 77 | } 78 | 79 | /** 80 | * Return coordinate for this cluster. If coordinate is not set is it 81 | * average calculated from markers. 82 | * 83 | * @return object Google_Maps_Coordinate 84 | */ 85 | public function getCoordinate() { 86 | $retval = $this->coordinate; 87 | if ('Google_Maps_Coordinate' != get_class($this->coordinate)) { 88 | if (count($this->getMarkers())) { 89 | $retval = $this->calculateCenter(); 90 | } else { 91 | /* Center was not set and could not calculate. Return default. */ 92 | return new Google_Maps_Coordinate(59.439000, 24.750100); 93 | } 94 | } 95 | return $retval; 96 | } 97 | 98 | /** 99 | * Return average center of markers 100 | * 101 | * @return object Google_Maps_Coordinate 102 | */ 103 | public function calculateCenter() { 104 | /* Calculate average lat and lon of markers. */ 105 | $lat_sum = $lon_sum = 0; 106 | foreach ($this->getMarkers() as $marker) { 107 | $lat_sum += $marker->getLat(); 108 | $lon_sum += $marker->getLon(); 109 | } 110 | $lat_avg = $lat_sum / count($this->getMarkers()); 111 | $lon_avg = $lon_sum / count($this->getMarkers()); 112 | 113 | return new Google_Maps_Coordinate($lat_avg, $lon_avg); 114 | } 115 | 116 | public function __toString() { 117 | $retval = sprintf($this->getFormat(), $this->getLat(), $this->getLon(), 118 | $this->getSize(), $this->getColor(), $this->getCharacter()); 119 | return preg_replace('/,$/', '', $retval); 120 | } 121 | 122 | } -------------------------------------------------------------------------------- /Google/Maps/Math.php: -------------------------------------------------------------------------------- 1 | getLat(); 28 | $lon1 = $location_1->getLon(); 29 | $lat2 = $location_2->getLat(); 30 | $lon2 = $location_2->getLon(); 31 | $d = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + 32 | cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon1) - deg2rad($lon2)); 33 | return 6371.0 * acos($d); 34 | } 35 | 36 | static public function HaversineDistance($location_1, $location_2) { 37 | /* 38 | var R = 6371; // km 39 | var dLat = (lat2-lat1).toRad(); 40 | var dLon = (lon2-lon1).toRad(); 41 | var a = Math.sin(dLat/2) * Math.sin(dLat/2) + 42 | Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 43 | Math.sin(dLon/2) * Math.sin(dLon/2); 44 | var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 45 | var d = R * c; 46 | */ 47 | $lat1 = $location_1->getLat(); 48 | $lon1 = $location_1->getLon(); 49 | $lat2 = $location_2->getLat(); 50 | $lon2 = $location_2->getLon(); 51 | $latd = deg2rad($lat2 - $lat1); 52 | $lond = deg2rad($lon2 - $lon1); 53 | $a = sin($latd / 2) * sin($latd / 2) + 54 | cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * 55 | sin($lond / 2) * sin($lond / 2); 56 | $c = 2 * atan2(sqrt($a), sqrt(1 - $a)); 57 | return 6371.0 * $c; 58 | } 59 | 60 | } 61 | 62 | /* 63 | $coord_1 = new Google_Maps_Coordinate('58.378700', '26.731110'); 64 | $coord_2 = new Google_Maps_Coordinate('58.379646', '26.764090'); 65 | 66 | print Google_Maps_Math::GreatCirleDistance($coord_1, $coord_2); 67 | print "\n"; 68 | print Google_Maps_Math::HaversineDistance($coord_1, $coord_2); 69 | print "\n"; 70 | print Google_Maps_Math::distance($coord_2, $coord_1); 71 | print "\n"; 72 | */ 73 | -------------------------------------------------------------------------------- /Google/Maps/Mercator.php: -------------------------------------------------------------------------------- 1 | $property; 37 | } 38 | } elseif (strpos($method, 'set') === 0) { 39 | $property = Google_Maps_Overload::underscore(substr($method, 3)); 40 | if (array_key_exists($property, $var)) { 41 | $this->$property = $params[0]; 42 | $retval = null; 43 | } 44 | } 45 | return $retval; 46 | } 47 | 48 | /** 49 | * Set object properties from array. 50 | * 51 | * @param array $params Values for object properties as associative array. 52 | */ 53 | public function setProperties($params) { 54 | if (is_array($params)) { 55 | foreach ($params as $key => $value) { 56 | $method = 'set' . $key; 57 | $this->$method($value); 58 | } 59 | } 60 | } 61 | 62 | /** 63 | * Transform CamelCapsed string into lowercase with underscore. 64 | * 65 | * @param string $word For example FooBar666 66 | * @return string For example foo_bar_666 67 | */ 68 | protected static function underscore($word) { 69 | $underscored = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $word)); 70 | $underscored = strtolower(preg_replace('/([0-9])([a-z])/', '\\1_\\2', $underscored)); 71 | $underscored = strtolower(preg_replace('/([a-z])([0-9])/', '\\1_\\2', $underscored)); 72 | $underscored = preg_replace('/__/', '_', $underscored); 73 | return $underscored; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /Google/Maps/Path.php: -------------------------------------------------------------------------------- 1 | setCoordinate($location); 31 | $this->setProperties($params); 32 | } 33 | 34 | /** 35 | * Set the coordinate of current path object. 36 | * 37 | * @param object $location Google_Maps_Coordinate|Point 38 | */ 39 | public function setCoordinate($location) { 40 | $this->coordinate = $location->toCoordinate(); 41 | } 42 | 43 | /** 44 | * Return path as coordinate in Google Maps. 45 | * 46 | * @return object Google_Maps_Coordinate 47 | */ 48 | public function toCoordinate() { 49 | return $this->getCoordinate(); 50 | } 51 | 52 | /** 53 | * Return path as pixel point in Google Maps. 54 | * 55 | * @return object Google_Maps_Point 56 | */ 57 | public function toPoint() { 58 | return $this->getCoordinate()->toPoint(); 59 | } 60 | 61 | /** 62 | * Return latitude of path coordinate. 63 | * 64 | * @return float Latitude 65 | */ 66 | public function getLat() { 67 | return $this->getCoordinate()->getLat(); 68 | } 69 | 70 | /** 71 | * Return longitude of path coordinate. 72 | * 73 | * @return float Longitude 74 | */ 75 | public function getLon() { 76 | return $this->getCoordinate()->getLon(); 77 | } 78 | 79 | public function __toString() { 80 | return $this->getLat() . ',' . $this->getLon(); 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /Google/Maps/Point.php: -------------------------------------------------------------------------------- 1 | setX($x); 35 | $this->setY($y); 36 | } 37 | 38 | /** 39 | * Return point as coordinate. 40 | * 41 | * @return object Google_Maps_Coordinate 42 | */ 43 | public function toCoordinate() { 44 | $x = $this->getX(); 45 | $y = $this->gety(); 46 | $lat = Google_Maps_Mercator::YToLat($y); 47 | $lon = Google_Maps_Mercator::XToLon($x); 48 | return new Google_Maps_Coordinate($lat, $lon); 49 | } 50 | 51 | /** 52 | * Return point as point in Google Maps. This method 53 | * exists only to provide unified API between coordinate and 54 | * point objects. 55 | * 56 | * @return object Google_Maps_Point 57 | */ 58 | public function toPoint() { 59 | return $this; 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /Google/Maps/Static.php: -------------------------------------------------------------------------------- 1 | setProperties($params); 61 | /* 62 | if (false === $this->getClusterer()) { 63 | $this->setClusterer(Google_Maps_Clusterer::create('none')); 64 | } 65 | */ 66 | } 67 | 68 | /** 69 | * Return center of the map. If center is not set is it calculated from markers. 70 | * If map has no markers return default center (which is Tallinn). 71 | * 72 | * @return object Google_Maps_Coordinate 73 | */ 74 | public function getCenter() { 75 | $retval = $this->center; 76 | if ('Google_Maps_Coordinate' != get_class($this->center)) { 77 | if (count($this->getMarkers())) { 78 | $retval = $this->calculateCenter(); 79 | } else { 80 | /* Center was not set and could not calculate. Return default. */ 81 | return new Google_Maps_Coordinate(59.439000, 24.750100); 82 | } 83 | } 84 | return $retval; 85 | } 86 | 87 | /** 88 | * Set center of the map. Converts lat,lon string to Google_Maps_Coordinate 89 | * when needed. 90 | * 91 | * @param mixed lat,lon string, Google_Maps_Coordinate or Google_Maps_Point 92 | */ 93 | 94 | public function setCenter($location) { 95 | if ($location instanceof Google_Maps_Location) { 96 | $this->center = $location->toCoordinate(); 97 | } else { 98 | list($lat, $lon) = explode(',', $location); 99 | $lat = trim($lat); 100 | $lon = trim($lon); 101 | $this->center = new Google_Maps_Coordinate($lat, $lon); 102 | } 103 | } 104 | 105 | /** 106 | * Return calculated center of the map. 107 | * 108 | * @return object Google_Maps_Coordinate 109 | */ 110 | public function calculateCenter() { 111 | /* Calculate average lat and lon of markers. */ 112 | $lat_sum = $lon_sum = 0; 113 | foreach ($this->getMarkers() as $marker) { 114 | $lat_sum += $marker->getLat(); 115 | $lon_sum += $marker->getLon(); 116 | } 117 | $lat_avg = $lat_sum / count($this->getMarkers()); 118 | $lon_avg = $lon_sum / count($this->getMarkers()); 119 | 120 | return new Google_Maps_Coordinate($lat_avg, $lon_avg); 121 | } 122 | 123 | /** 124 | * Set and return zoom of the map so all markers fit to screen. Takes map 125 | * center into account when it is set. 126 | * 127 | * TODO zoomToFit() does not respect maz and min zoom. 128 | * 129 | * @return integer New zoom level. 130 | */ 131 | public function zoomToFit() { 132 | $zoom = 21; 133 | $found = false; 134 | if (count($this->markers) > 0) { 135 | $marker_bounds = $this->getMarkerBounds(); 136 | while ($found == false) { 137 | $map_bounds = $this->getBounds($zoom); 138 | $found = $map_bounds->contains($marker_bounds); 139 | $zoom--; 140 | } 141 | } else $zoom = 0; // zoom Map monde 142 | $this->setZoom($zoom + 1); 143 | return $zoom; 144 | } 145 | 146 | /** 147 | * Set visible infowindow. Data usually passed from querystring. 148 | * 149 | * @param string id of infowindow 150 | * @return integer number of visible infowindows in map. 151 | */ 152 | public function setInfowindow($id = '') { 153 | foreach ($this->getInfowindows() as $infowindow) { 154 | if ($infowindow->getMarker()->getId() == $id) { 155 | $infowindow->show(); 156 | } 157 | } 158 | /* TODO Hardcoded because there can be only one infowindow open ATM. */ 159 | return 1; 160 | } 161 | 162 | 163 | /** 164 | * Return smallest possible bounds where all markers fit in. 165 | * 166 | * @return object Google_Maps_Bounds 167 | */ 168 | public function getMarkerBounds() { 169 | return new Google_Maps_Bounds($this->getMarkers()); 170 | } 171 | 172 | /** 173 | * Draw marker bounds to map. Useful for debugging. 174 | * 175 | */ 176 | public function showMarkerBounds() { 177 | $marker_bounds = $this->getMarkerBounds(); 178 | $bounds_path = $marker_bounds->getPath(); 179 | $this->setPath($bounds_path); 180 | } 181 | 182 | /** 183 | * Return map width in pixels. 184 | * 185 | * @return integer Map width in pixels 186 | */ 187 | public function getWidth() { 188 | list($width, $height) = explode('x', $this->getSize()); 189 | return $width; 190 | } 191 | 192 | /** 193 | * Return map height in pixels. 194 | * 195 | * @return integer Map height in pixels 196 | */ 197 | public function getHeight() { 198 | list($width, $height) = explode('x', $this->getSize()); 199 | return $height; 200 | } 201 | 202 | /** 203 | * Return bounds of current map. 204 | * 205 | * @return object Google_Maps_Bounds 206 | */ 207 | public function getBounds($zoom = '') { 208 | $old_zoom = $this->getZoom(); 209 | if ($zoom) { 210 | $this->setZoom($zoom); 211 | } 212 | $delta_x = round($this->getWidth() / 2); 213 | $delta_y = round($this->getHeight() / 2); 214 | 215 | $lat = $this->getCenter()->getLat(); 216 | $lon = $this->getCenter()->getLon(); 217 | $zoom = $this->getZoom(); 218 | 219 | $north = Google_Maps_Mercator::adjustLatByPixels($lat, $delta_y * -1, $zoom); 220 | $south = Google_Maps_Mercator::adjustLatByPixels($lat, $delta_y, $zoom); 221 | $west = Google_Maps_Mercator::adjustLonByPixels($lon, $delta_x * -1, $zoom); 222 | $east = Google_Maps_Mercator::adjustLonByPixels($lon, $delta_x, $zoom); 223 | 224 | $north_west = new Google_Maps_Coordinate($north, $west); 225 | $north_east = new Google_Maps_Coordinate($north, $east); 226 | $south_west = new Google_Maps_Coordinate($south, $west); 227 | $south_east = new Google_Maps_Coordinate($south, $east); 228 | 229 | $this->setZoom($old_zoom); 230 | 231 | return new Google_Maps_Bounds(array($north_west, $south_east)); 232 | } 233 | 234 | /** 235 | * Return markers of current map in either array or as a string 236 | * which can be used in image URL. If bounds is give return only markers 237 | * which are inside bounds. 238 | * 239 | * @param string $type Either 'array' of 'string'. 240 | * @param mixed $bounds false or Google_Maps_Bounds 241 | * @return mixed Array or string. 242 | */ 243 | public function getMarkers($type = 'array', $bounds=false) { 244 | $markers = array(); 245 | if ($bounds) { 246 | foreach ($this->markers as $marker) { 247 | if ($bounds->contains($marker)) { 248 | $markers[] = $marker; 249 | } 250 | } 251 | } else { 252 | $markers = $this->markers; 253 | } 254 | if ('string' == $type) { 255 | $format = $this->marker_formats[$this->getZoom() - 1]; 256 | $retval = ''; 257 | if (is_array($markers)) { 258 | foreach ($markers as $marker) { 259 | $marker->setFormat($format); 260 | $retval[] = preg_replace('/\|$/', '',$marker); 261 | } 262 | } else { 263 | $retval = preg_replace('/\|$/', '', $retval); 264 | } 265 | } else { 266 | $retval = $markers; 267 | } 268 | return $retval; 269 | } 270 | 271 | /** 272 | * Return markers of current map in either array or as a string 273 | * which can be used in image URL. 274 | * 275 | * @param mixed array or string 276 | * @return integer number of markers 277 | */ 278 | public function setMarkers($markers) { 279 | 280 | if (is_array($markers)) { 281 | $this->markers = $markers; 282 | } elseif (is_string($markers)) { 283 | $marker_array = explode('|', $markers); 284 | $this->markers = array(); 285 | foreach ($marker_array as $marker) { 286 | unset($params); 287 | @list($lat, $lon, $color) = explode(',', $marker); 288 | $params['color'] = $color; 289 | $coordinate = new Google_Maps_Coordinate($lat, $lon); 290 | $this->addMarker(new Google_Maps_Marker($coordinate, $params)); 291 | } 292 | } else { 293 | $this->markers = array(); 294 | } 295 | 296 | return count($this->getMarkers()); 297 | } 298 | 299 | /** 300 | * Return clustered markers of current map in either array or as a string 301 | * which can be used in image URL. If bounds is give return only markers 302 | * which are inside bounds. 303 | * 304 | * @param string $type Either 'array' of 'string'. 305 | * @param mixed $bounds false or Google_Maps_Bounds 306 | * @return mixed Array or string. 307 | */ 308 | public function getClusteredMarkers($type = 'array', $bounds=false) { 309 | $markers = $this->getMarkers('array', $bounds); 310 | $markers = $this->getClusterer()->process($markers, $this); 311 | 312 | if ('string' == $type) { 313 | $format = $this->marker_formats[$this->getZoom() - 1]; 314 | $retval = ''; 315 | if (is_array($markers)) { 316 | foreach ($markers as $marker) { 317 | $marker->setFormat($format); 318 | $retval .= $marker; 319 | $retval .= '|'; 320 | } 321 | $retval = preg_replace('/\|$/', '', $retval); 322 | } 323 | } else { 324 | $retval = $markers; 325 | } 326 | return $retval; 327 | } 328 | 329 | 330 | /** 331 | * Return infowindows of current map as array. If bounds is give return 332 | * only infowindows which are inside bounds. 333 | * 334 | * @param mixed $bounds false or Google_Maps_Bounds 335 | * @return mixed Array or string. 336 | */ 337 | public function getInfowindows($bounds=false) { 338 | $infowindows = array(); 339 | if ($bounds) { 340 | foreach ($this->infowindows as $infowindow) { 341 | if ($bounds->contains($infowindow->getMarker())) { 342 | $infowindows[] = $infowindow; 343 | } 344 | } 345 | } else { 346 | $infowindows = $this->infowindows; 347 | } 348 | return $infowindows; 349 | } 350 | 351 | /** 352 | * Return path of current map in either array or as a string 353 | * which can be used in image URL. 354 | * 355 | * @param string $type Either 'array' of 'string'. 356 | * @return mixed Array or string. 357 | */ 358 | public function getPath($type = 'array') { 359 | $retval = $this->path; 360 | if ('string' == $type && is_array($this->path)) { 361 | $retval = ''; 362 | foreach ($this->path as $coordinate) { 363 | $retval .= $coordinate; 364 | $retval .= '|'; 365 | } 366 | } 367 | return $retval; 368 | } 369 | 370 | /** 371 | * Add marker to map. 372 | * 373 | * @param object Google_Maps_Marker 374 | * @return integer Total number of markers in map. 375 | */ 376 | public function addMarker($marker) { 377 | $this->markers[] = $marker; 378 | return count($this->getMarkers()); 379 | } 380 | 381 | /** 382 | * Remove marker from map. 383 | * 384 | * @param object Google_Maps_Marker 385 | * @return integer Total number of markers in map. 386 | */ 387 | public function removeMarker($marker) { 388 | $markers = array(); 389 | foreach ($this->getMarkers() as $target) { 390 | if ($marker != $target) { 391 | $markers[] = $target; 392 | } 393 | } 394 | $this->setMarkers($markers); 395 | return count($markers); 396 | } 397 | 398 | /** 399 | * Add control to map. 400 | * 401 | * @param object Google_Maps_Control 402 | * @return integer Total number of controls in map. 403 | */ 404 | public function addControl($control) { 405 | $this->controls[] = $control; 406 | return count($this->getControls()); 407 | } 408 | 409 | /** 410 | * Remove control from map. 411 | * 412 | * @param object Google_Maps_Control 413 | * @return integer Total number of controls in map. 414 | */ 415 | public function removeControl() { 416 | 417 | } 418 | 419 | /** 420 | * Add infowindow to map. 421 | * 422 | * @param object Google_Maps_Infowindow 423 | * @return integer Total number of infowindows in map. 424 | */ 425 | public function addInfowindow($infowindow) { 426 | $this->infowindows[] = $infowindow; 427 | return count($this->getInfowindows()); 428 | } 429 | 430 | /** 431 | * Remove infowindow from map. 432 | * 433 | * @param object Google_Maps_Infowindow 434 | * @return integer Total number of infowindows in map. 435 | */ 436 | public function removeInfowindow() { 437 | 438 | } 439 | 440 | /** 441 | * Zoom out one level 442 | * 443 | * @return integer New zoom level. 444 | */ 445 | public function zoomOut() { 446 | $new_zoom = max($this->getMinZoom(), $this->getZoom() - 1); 447 | $this->setZoom($new_zoom); 448 | return $new_zoom; 449 | } 450 | 451 | /** 452 | * Zoom in one level 453 | * 454 | * @return integer New zoom level. 455 | */ 456 | public function zoomIn() { 457 | $new_zoom = min($this->getMaxZoom(), $this->getZoom() + 1); 458 | $this->setZoom($new_zoom); 459 | return $new_zoom; 460 | } 461 | 462 | /** 463 | * Pan north by pixels 464 | * 465 | * @return object Google_Maps_Coordinate 466 | */ 467 | public function panNorth($pixels) { 468 | $center = $this->getCenter(); 469 | $new_lat = Google_Maps_Mercator::adjustLatByPixels($center->getLat(), $pixels * -1, $this->getZoom()); 470 | $center->setLat($new_lat); 471 | $this->setCenter($center); 472 | return $center; 473 | } 474 | 475 | /** 476 | * Pan south by pixels 477 | * 478 | * @return object Google_Maps_Coordinate 479 | */ 480 | public function panSouth($pixels) { 481 | $center = $this->getCenter(); 482 | $new_lat = Google_Maps_Mercator::adjustLatByPixels($center->getLat(), $pixels, $this->getZoom()); 483 | $center->setLat($new_lat); 484 | $this->setCenter($center); 485 | return $center; 486 | } 487 | 488 | /** 489 | * Pan west by pixels 490 | * 491 | * @return object Google_Maps_Coordinate 492 | */ 493 | public function panWest($pixels) { 494 | $center = $this->getCenter(); 495 | $new_lon = Google_Maps_Mercator::adjustLonByPixels($center->getLon(), $pixels * -1, $this->getZoom()); 496 | $center->setLon($new_lon); 497 | $this->setCenter($center); 498 | return $center; 499 | } 500 | 501 | /** 502 | * Pan east by pixels 503 | * 504 | * @return object Google_Maps_Coordinate 505 | */ 506 | public function panEast($pixels) { 507 | $center = $this->getCenter(); 508 | $new_lon = Google_Maps_Mercator::adjustLonByPixels($center->getLon(), $pixels, $this->getZoom()); 509 | $center->setLon($new_lon); 510 | $this->setCenter($center); 511 | return $center; 512 | } 513 | 514 | 515 | /** 516 | * Return image URL query string for current map. 517 | * 518 | * @return string Static map image URL querystring. 519 | */ 520 | /* 521 | TODO $include_all here is freaking unelegant 522 | */ 523 | public function toQueryString($include_all = false) { 524 | $url['center'] = $this->getCenter()->__toString(); 525 | 526 | $url['infowindow'] = ''; 527 | foreach ($this->getInfowindows() as $infowindow) { 528 | if ($infowindow->isVisible()) { 529 | $url['infowindow'] = $infowindow->getMarker()->getId(); 530 | } 531 | } 532 | 533 | $url['zoom'] = $this->getZoom(); 534 | 535 | if ($include_all) { 536 | if ($this->getClusterer()) { 537 | $url['markers'] = $this->getClusteredMarkers('string', $this->getBounds()); 538 | } else { 539 | if (count($this->markers) > 0) { 540 | $markers = $this->getMarkers('string', $this->getBounds()); 541 | $url['markers'] = $markers; 542 | } 543 | } 544 | $url['path'] = $this->getPath('string'); 545 | $url['size'] = $this->getSize(); 546 | $url['maptype'] = $this->getType(); 547 | $url['key'] = $this->getKey(); 548 | } 549 | 550 | $retval = http_build_query($url,'','&'); 551 | $retval = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $retval); 552 | return str_replace('&', '&', $retval); 553 | } 554 | 555 | /** 556 | * Return image URL for current map. 557 | * 558 | * @return string Static map image URL. 559 | */ 560 | public function toUrl($prefix='http://maps.googleapis.com/maps/api/staticmap?', $full=true) { 561 | return $prefix . $this->toQueryString($full); 562 | } 563 | 564 | /** 565 | * Return image tag for current map. 566 | * 567 | * @return string Static map image URL. 568 | */ 569 | public function toImgTag($id = '', $class = '', $addlink = FALSE) { 570 | $retval = sprintf('', 571 | (trim($id)) ? 'id="'.$id.'"' : '', 572 | (trim($class)) ? 'class="'.$class.'"' : '', 573 | $this->toUrl().'&sensor=false', $this->getWidth(), $this->getHeight()); 574 | if ($addlink) { 575 | if (count($this->markers) > 0) { 576 | $center = $this->calculateCenter(); 577 | 578 | return sprintf('%s', 579 | (trim($id)) ? 'id="a_'.$id.'"' : '', 580 | $center->getLat(), 581 | $center->getLon(), 582 | $this->zoomToFit(), 583 | $retval); 584 | } else { 585 | return sprintf('%s', 586 | (trim($id)) ? 'id="a_'.$id.'"' : '', 587 | $this->zoomToFit(), 588 | $retval); 589 | } 590 | 591 | } else { 592 | return $retval; 593 | } 594 | } 595 | 596 | /** 597 | * Return full HTML for current map. Including controls and markers. 598 | * 599 | * @return string Static map HTML. 600 | */ 601 | public function toHtml() { 602 | $retval = sprintf('
', 603 | $this->getWidth(), $this->getHeight()); 604 | $retval .= "\n"; 605 | $retval .= '' . "\n"; 606 | /* Include only markers inside map bounds to keep HTML size smaller. */ 607 | foreach ($this->getMarkers('array', $this->getBounds()) as $marker) { 608 | $retval .= $marker->toArea($this) . "\n"; 609 | } 610 | $retval .= '' . "\n"; 611 | $retval .= $this->toImgTag(); 612 | $retval .= '
' . "\n"; 613 | foreach ($this->getControls() as $control) { 614 | $retval .= $control->toHtml($this) . "\n"; 615 | } 616 | 617 | /* Include only infowindows inside map bounds to keep HTML size smaller. */ 618 | foreach ($this->getInfowindows($this->getBounds()) as $infowindow) { 619 | $retval .= $infowindow->toHtml($this) . "\n"; 620 | } 621 | 622 | $retval .= '
' . "\n"; 623 | $retval .= '
' . "\n"; 624 | 625 | return $retval; 626 | } 627 | 628 | public function __toString() { 629 | return $this->toUrl(); 630 | } 631 | 632 | } 633 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This code is Alpha quality. API might change at any point. You have been warned. 2 | If you have any patches or suggestions drop me a line: 3 | 4 | tuupola@appelsiini.net 5 | http://www.appelsiini.net/ -------------------------------------------------------------------------------- /cities.kml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Kabul 6 | 7 | 69.11,34.28,0.0 8 | 9 | 10 | 11 | Tirane 12 | 13 | 19.49,41.18,0.0 14 | 15 | 16 | 17 | Algiers 18 | 19 | 3.08,36.42,0.0 20 | 21 | 22 | 23 | Pago Pago 24 | 25 | -170.43,-14.16,0.0 26 | 27 | 28 | 29 | Andorra la Vella 30 | 31 | 1.32,42.31,0.0 32 | 33 | 34 | 35 | Luanda 36 | 37 | 13.15,-8.5,0.0 38 | 39 | 40 | 41 | W. Indies 42 | 43 | -61.48,17.2,0.0 44 | 45 | 46 | 47 | Buenos Aires 48 | 49 | -60,-36.3,0.0 50 | 51 | 52 | 53 | Yerevan 54 | 55 | 44.31,40.1,0.0 56 | 57 | 58 | 59 | Oranjestad 60 | 61 | -70.02,12.32,0.0 62 | 63 | 64 | 65 | Canberra 66 | 67 | 149.08,-35.15,0.0 68 | 69 | 70 | 71 | Vienna 72 | 73 | 16.22,48.12,0.0 74 | 75 | 76 | 77 | Baku 78 | 79 | 49.56,40.29,0.0 80 | 81 | 82 | 83 | Nassau 84 | 85 | -77.2,25.05,0.0 86 | 87 | 88 | 89 | Manama 90 | 91 | 50.3,26.1,0.0 92 | 93 | 94 | 95 | Dhaka 96 | 97 | 90.26,23.43,0.0 98 | 99 | 100 | 101 | Bridgetown 102 | 103 | -59.3,13.05,0.0 104 | 105 | 106 | 107 | Minsk 108 | 109 | 27.3,53.52,0.0 110 | 111 | 112 | 113 | Brussels 114 | 115 | 4.21,50.51,0.0 116 | 117 | 118 | 119 | Belmopan 120 | 121 | -88.3,17.18,0.0 122 | 123 | 124 | 125 | Porto-Novo (constitutional cotonou (seat of gvnt) 126 | 127 | 2.42,6.23,0.0 128 | 129 | 130 | 131 | Thimphu 132 | 133 | 89.45,27.31,0.0 134 | 135 | 136 | 137 | La Paz (adm.)/sucre (legislative) 138 | 139 | -68.1,-16.2,0.0 140 | 141 | 142 | 143 | Sarajevo 144 | 145 | 18.26,43.52,0.0 146 | 147 | 148 | 149 | Gaborone 150 | 151 | 25.57,-24.45,0.0 152 | 153 | 154 | 155 | Brasilia 156 | 157 | -47.55,-15.47,0.0 158 | 159 | 160 | 161 | Road Town 162 | 163 | -64.37,18.27,0.0 164 | 165 | 166 | 167 | Bandar Seri Begawan 168 | 169 | 115,4.52,0.0 170 | 171 | 172 | 173 | Sofia 174 | 175 | 23.2,42.45,0.0 176 | 177 | 178 | 179 | Ouagadougou 180 | 181 | -1.3,12.15,0.0 182 | 183 | 184 | 185 | Bujumbura 186 | 187 | 29.18,-3.16,0.0 188 | 189 | 190 | 191 | Phnom Penh 192 | 193 | 104.55,11.33,0.0 194 | 195 | 196 | 197 | Yaounde 198 | 199 | 11.35,3.5,0.0 200 | 201 | 202 | 203 | Ottawa 204 | 205 | -75.42,45.27,0.0 206 | 207 | 208 | 209 | Praia 210 | 211 | -23.34,15.02,0.0 212 | 213 | 214 | 215 | George Town 216 | 217 | -81.24,19.2,0.0 218 | 219 | 220 | 221 | Bangui 222 | 223 | 18.35,4.23,0.0 224 | 225 | 226 | 227 | N'Djamena 228 | 229 | 14.59,12.1,0.0 230 | 231 | 232 | 233 | Santiago 234 | 235 | -70.4,-33.24,0.0 236 | 237 | 238 | 239 | Beijing 240 | 241 | 116.2,39.55,0.0 242 | 243 | 244 | 245 | Bogota 246 | 247 | -74,4.34,0.0 248 | 249 | 250 | 251 | Moroni 252 | 253 | 43.16,-11.4,0.0 254 | 255 | 256 | 257 | Brazzaville 258 | 259 | 15.12,-4.09,0.0 260 | 261 | 262 | 263 | San Jose 264 | 265 | -84.02,9.55,0.0 266 | 267 | 268 | 269 | Yamoussoukro 270 | 271 | -5.17,6.49,0.0 272 | 273 | 274 | 275 | Zagreb 276 | 277 | 15.58,45.5,0.0 278 | 279 | 280 | 281 | Havana 282 | 283 | -82.22,23.08,0.0 284 | 285 | 286 | 287 | Nicosia 288 | 289 | 33.25,35.1,0.0 290 | 291 | 292 | 293 | Prague 294 | 295 | 14.22,50.05,0.0 296 | 297 | 298 | 299 | P'yongyang 300 | 301 | 125.3,39.09,0.0 302 | 303 | 304 | 305 | Kinshasa 306 | 307 | 15.15,-4.2,0.0 308 | 309 | 310 | 311 | Copenhagen 312 | 313 | 12.34,55.41,0.0 314 | 315 | 316 | 317 | Djibouti 318 | 319 | 42.2,11.08,0.0 320 | 321 | 322 | 323 | Roseau 324 | 325 | -61.24,15.2,0.0 326 | 327 | 328 | 329 | Santo Domingo 330 | 331 | -69.59,18.3,0.0 332 | 333 | 334 | 335 | Dili 336 | 337 | 125.34,-8.29,0.0 338 | 339 | 340 | 341 | Quito 342 | 343 | -78.35,-0.15,0.0 344 | 345 | 346 | 347 | Cairo 348 | 349 | 31.14,30.01,0.0 350 | 351 | 352 | 353 | San Salvador 354 | 355 | -89.1,13.4,0.0 356 | 357 | 358 | 359 | Malabo 360 | 361 | 8.5,3.45,0.0 362 | 363 | 364 | 365 | Asmara 366 | 367 | 38.55,15.19,0.0 368 | 369 | 370 | 371 | Tallinn 372 | 373 | 24.48,59.22,0.0 374 | 375 | 376 | 377 | Addis Ababa 378 | 379 | 38.42,9.02,0.0 380 | 381 | 382 | 383 | Stanley 384 | 385 | -59.51,-51.4,0.0 386 | 387 | 388 | 389 | Torshavn 390 | 391 | -6.56,62.05,0.0 392 | 393 | 394 | 395 | Suva 396 | 397 | 178.3,-18.06,0.0 398 | 399 | 400 | 401 | Helsinki 402 | 403 | 25.03,60.15,0.0 404 | 405 | 406 | 407 | Paris 408 | 409 | 2.2,48.5,0.0 410 | 411 | 412 | 413 | Cayenne 414 | 415 | -52.18,5.05,0.0 416 | 417 | 418 | 419 | Papeete 420 | 421 | -149.34,-17.32,0.0 422 | 423 | 424 | 425 | Libreville 426 | 427 | 9.26,0.25,0.0 428 | 429 | 430 | 431 | Banjul 432 | 433 | -16.4,13.28,0.0 434 | 435 | 436 | 437 | T'bilisi 438 | 439 | 44.5,41.43,0.0 440 | 441 | 442 | 443 | Berlin 444 | 445 | 13.25,52.3,0.0 446 | 447 | 448 | 449 | Accra 450 | 451 | -0.06,5.35,0.0 452 | 453 | 454 | 455 | Athens 456 | 457 | 23.46,37.58,0.0 458 | 459 | 460 | 461 | Nuuk 462 | 463 | -51.35,64.1,0.0 464 | 465 | 466 | 467 | Basse-Terre 468 | 469 | -61.44,16,0.0 470 | 471 | 472 | 473 | Guatemala 474 | 475 | -90.22,14.4,0.0 476 | 477 | 478 | 479 | St. Peter Port 480 | 481 | -2.33,49.26,0.0 482 | 483 | 484 | 485 | Conakry 486 | 487 | -13.49,9.29,0.0 488 | 489 | 490 | 491 | Bissau 492 | 493 | -15.45,11.45,0.0 494 | 495 | 496 | 497 | Georgetown 498 | 499 | -58.12,6.5,0.0 500 | 501 | 502 | 503 | Port-au-Prince 504 | 505 | -72.2,18.4,0.0 506 | 507 | 508 | 509 | xxx 510 | 511 | 74,-53,0.0 512 | 513 | 514 | 515 | Tegucigalpa 516 | 517 | -87.14,14.05,0.0 518 | 519 | 520 | 521 | Budapest 522 | 523 | 19.05,47.29,0.0 524 | 525 | 526 | 527 | Reykjavik 528 | 529 | -21.57,64.1,0.0 530 | 531 | 532 | 533 | New Delhi 534 | 535 | 77.13,28.37,0.0 536 | 537 | 538 | 539 | Jakarta 540 | 541 | 106.49,-6.09,0.0 542 | 543 | 544 | 545 | Tehran 546 | 547 | 51.3,35.44,0.0 548 | 549 | 550 | 551 | Baghdad 552 | 553 | 44.3,33.2,0.0 554 | 555 | 556 | 557 | Dublin 558 | 559 | -6.15,53.21,0.0 560 | 561 | 562 | 563 | Jerusalem 564 | 565 | 35.1,31.71,0.0 566 | 567 | 568 | 569 | Rome 570 | 571 | 12.29,41.54,0.0 572 | 573 | 574 | 575 | Kingston 576 | 577 | -76.5,18,0.0 578 | 579 | 580 | 581 | Amman 582 | 583 | 35.52,31.57,0.0 584 | 585 | 586 | 587 | Astana 588 | 589 | 71.3,51.1,0.0 590 | 591 | 592 | 593 | Nairobi 594 | 595 | 36.48,-1.17,0.0 596 | 597 | 598 | 599 | Tarawa 600 | 601 | 173,1.3,0.0 602 | 603 | 604 | 605 | Kuwait 606 | 607 | 48,29.3,0.0 608 | 609 | 610 | 611 | Bishkek 612 | 613 | 74.46,42.54,0.0 614 | 615 | 616 | 617 | Vientiane 618 | 619 | 102.36,17.58,0.0 620 | 621 | 622 | 623 | Riga 624 | 625 | 24.08,56.53,0.0 626 | 627 | 628 | 629 | Beirut 630 | 631 | 35.31,33.53,0.0 632 | 633 | 634 | 635 | Maseru 636 | 637 | 27.3,-29.18,0.0 638 | 639 | 640 | 641 | Monrovia 642 | 643 | -10.47,6.18,0.0 644 | 645 | 646 | 647 | Tripoli 648 | 649 | 13.07,32.49,0.0 650 | 651 | 652 | 653 | Vaduz 654 | 655 | 9.31,47.08,0.0 656 | 657 | 658 | 659 | Vilnius 660 | 661 | 25.19,54.38,0.0 662 | 663 | 664 | 665 | Luxembourg 666 | 667 | 6.09,49.37,0.0 668 | 669 | 670 | 671 | Macau 672 | 673 | 113.33,22.12,0.0 674 | 675 | 676 | 677 | Antananarivo 678 | 679 | 47.31,-18.55,0.0 680 | 681 | 682 | 683 | Lilongwe 684 | 685 | 33.48,-14,0.0 686 | 687 | 688 | 689 | Kuala Lumpur 690 | 691 | 101.41,3.09,0.0 692 | 693 | 694 | 695 | Male 696 | 697 | 73.28,4,0.0 698 | 699 | 700 | 701 | Bamako 702 | 703 | -7.55,12.34,0.0 704 | 705 | 706 | 707 | Valletta 708 | 709 | 14.31,35.54,0.0 710 | 711 | 712 | 713 | Fort-de-France 714 | 715 | -61.02,14.36,0.0 716 | 717 | 718 | 719 | Nouakchott 720 | 721 | 57.3,-20.1,0.0 722 | 723 | 724 | 725 | Mamoudzou 726 | 727 | 45.14,-12.48,0.0 728 | 729 | 730 | 731 | Mexico 732 | 733 | -99.1,19.2,0.0 734 | 735 | 736 | 737 | Palikir 738 | 739 | 158.09,6.55,0.0 740 | 741 | 742 | 743 | Chisinau 744 | 745 | 28.5,47.02,0.0 746 | 747 | 748 | 749 | Maputo 750 | 751 | 32.32,-25.58,0.0 752 | 753 | 754 | 755 | Yangon 756 | 757 | 96.2,16.45,0.0 758 | 759 | 760 | 761 | Windhoek 762 | 763 | 17.04,-22.35,0.0 764 | 765 | 766 | 767 | Kathmandu 768 | 769 | 85.2,27.45,0.0 770 | 771 | 772 | 773 | Amsterdam/The Hague (seat of Gvnt) 774 | 775 | 4.54,52.23,0.0 776 | 777 | 778 | 779 | Willemstad 780 | 781 | -69,12.05,0.0 782 | 783 | 784 | 785 | Noumea 786 | 787 | 166.3,-22.17,0.0 788 | 789 | 790 | 791 | Wellington 792 | 793 | 174.46,-41.19,0.0 794 | 795 | 796 | 797 | Managua 798 | 799 | -86.2,12.06,0.0 800 | 801 | 802 | 803 | Niamey 804 | 805 | 2.06,13.27,0.0 806 | 807 | 808 | 809 | Abuja 810 | 811 | 7.32,9.05,0.0 812 | 813 | 814 | 815 | Kingston 816 | 817 | 168.43,-45.2,0.0 818 | 819 | 820 | 821 | Saipan 822 | 823 | 145.45,15.12,0.0 824 | 825 | 826 | 827 | Oslo 828 | 829 | 10.45,59.55,0.0 830 | 831 | 832 | 833 | Masqat 834 | 835 | 58.36,23.37,0.0 836 | 837 | 838 | 839 | Islamabad 840 | 841 | 73.1,33.4,0.0 842 | 843 | 844 | 845 | Koror 846 | 847 | 134.28,7.2,0.0 848 | 849 | 850 | 851 | Panama 852 | 853 | -79.25,9,0.0 854 | 855 | 856 | 857 | Port Moresby 858 | 859 | 147.08,-9.24,0.0 860 | 861 | 862 | 863 | Asuncion 864 | 865 | -57.3,-25.1,0.0 866 | 867 | 868 | 869 | Lima 870 | 871 | -77,-12,0.0 872 | 873 | 874 | 875 | Manila 876 | 877 | 121.03,14.4,0.0 878 | 879 | 880 | 881 | Warsaw 882 | 883 | 21,52.13,0.0 884 | 885 | 886 | 887 | Lisbon 888 | 889 | -9.1,38.42,0.0 890 | 891 | 892 | 893 | San Juan 894 | 895 | -66.07,18.28,0.0 896 | 897 | 898 | 899 | Doha 900 | 901 | 51.35,25.15,0.0 902 | 903 | 904 | 905 | Seoul 906 | 907 | 126.58,37.31,0.0 908 | 909 | 910 | 911 | Bucuresti 912 | 913 | 26.1,44.27,0.0 914 | 915 | 916 | 917 | Moskva 918 | 919 | 37.35,55.45,0.0 920 | 921 | 922 | 923 | Kigali 924 | 925 | 30.04,-1.59,0.0 926 | 927 | 928 | 929 | Basseterre 930 | 931 | -62.43,17.17,0.0 932 | 933 | 934 | 935 | Castries 936 | 937 | -60.58,14.02,0.0 938 | 939 | 940 | 941 | Saint-Pierre 942 | 943 | -56.12,46.46,0.0 944 | 945 | 946 | 947 | Kingstown 948 | 949 | -61.1,13.1,0.0 950 | 951 | 952 | 953 | Apia 954 | 955 | -171.5,-13.5,0.0 956 | 957 | 958 | 959 | San Marino 960 | 961 | 12.3,43.55,0.0 962 | 963 | 964 | 965 | Sao Tome 966 | 967 | 6.39,0.1,0.0 968 | 969 | 970 | 971 | Riyadh 972 | 973 | 46.42,24.41,0.0 974 | 975 | 976 | 977 | Dakar 978 | 979 | -17.29,14.34,0.0 980 | 981 | 982 | 983 | Freetown 984 | 985 | -13.17,8.3,0.0 986 | 987 | 988 | 989 | Bratislava 990 | 991 | 17.07,48.1,0.0 992 | 993 | 994 | 995 | Ljubljana 996 | 997 | 14.33,46.04,0.0 998 | 999 | 1000 | 1001 | Honiara 1002 | 1003 | 159.57,-9.27,0.0 1004 | 1005 | 1006 | 1007 | Mogadishu 1008 | 1009 | 45.25,2.02,0.0 1010 | 1011 | 1012 | 1013 | Pretoria (adm.) / Cap Town (Legislative) / Bloemfontein (Judicial) 1014 | 1015 | 28.12,-25.44,0.0 1016 | 1017 | 1018 | 1019 | Madrid 1020 | 1021 | -3.45,40.25,0.0 1022 | 1023 | 1024 | 1025 | Khartoum 1026 | 1027 | 32.35,15.31,0.0 1028 | 1029 | 1030 | 1031 | Paramaribo 1032 | 1033 | -55.1,5.5,0.0 1034 | 1035 | 1036 | 1037 | Mbabane (Adm.) 1038 | 1039 | 31.06,-26.18,0.0 1040 | 1041 | 1042 | 1043 | Stockholm 1044 | 1045 | 18.03,59.2,0.0 1046 | 1047 | 1048 | 1049 | Bern 1050 | 1051 | 7.28,46.57,0.0 1052 | 1053 | 1054 | 1055 | Damascus 1056 | 1057 | 36.18,33.3,0.0 1058 | 1059 | 1060 | 1061 | Dushanbe 1062 | 1063 | 68.48,38.33,0.0 1064 | 1065 | 1066 | 1067 | Bangkok 1068 | 1069 | 100.35,13.45,0.0 1070 | 1071 | 1072 | 1073 | Skopje 1074 | 1075 | 21.26,42.01,0.0 1076 | 1077 | 1078 | 1079 | Lome 1080 | 1081 | 1.2,6.09,0.0 1082 | 1083 | 1084 | 1085 | Nuku'alofa 1086 | 1087 | -174,-21.1,0.0 1088 | 1089 | 1090 | 1091 | Tunis 1092 | 1093 | 10.11,36.5,0.0 1094 | 1095 | 1096 | 1097 | Ankara 1098 | 1099 | 32.54,39.57,0.0 1100 | 1101 | 1102 | 1103 | Ashgabat 1104 | 1105 | 57.5,38,0.0 1106 | 1107 | 1108 | 1109 | Funafuti 1110 | 1111 | 179.13,-8.31,0.0 1112 | 1113 | 1114 | 1115 | Kampala 1116 | 1117 | 32.3,0.2,0.0 1118 | 1119 | 1120 | 1121 | Kiev (Rus) 1122 | 1123 | 30.28,50.3,0.0 1124 | 1125 | 1126 | 1127 | Abu Dhabi 1128 | 1129 | 54.22,24.28,0.0 1130 | 1131 | 1132 | 1133 | London 1134 | 1135 | -0.05,51.36,0.0 1136 | 1137 | 1138 | 1139 | Dodoma 1140 | 1141 | 35.45,-6.08,0.0 1142 | 1143 | 1144 | 1145 | Washington DC 1146 | 1147 | -77.02,39.91,0.0 1148 | 1149 | 1150 | 1151 | Charlotte Amalie 1152 | 1153 | -64.56,18.21,0.0 1154 | 1155 | 1156 | 1157 | Montevideo 1158 | 1159 | -56.11,-34.5,0.0 1160 | 1161 | 1162 | 1163 | Tashkent 1164 | 1165 | 69.1,41.2,0.0 1166 | 1167 | 1168 | 1169 | Port-Vila 1170 | 1171 | 168.18,-17.45,0.0 1172 | 1173 | 1174 | 1175 | Caracas 1176 | 1177 | -66.55,10.3,0.0 1178 | 1179 | 1180 | 1181 | Hanoi 1182 | 1183 | 105.55,21.05,0.0 1184 | 1185 | 1186 | 1187 | Belgrade 1188 | 1189 | 20.37,44.5,0.0 1190 | 1191 | 1192 | 1193 | Lusaka 1194 | 1195 | 28.16,-15.28,0.0 1196 | 1197 | 1198 | 1199 | Harare 1200 | 1201 | 31.02,-17.43,0.0 1202 | 1203 | 1204 | 1205 | 1206 | -------------------------------------------------------------------------------- /cluster.html: -------------------------------------------------------------------------------- 1 | 3600000 8 | ); 9 | 10 | $cache = new Cache_Lite(); 11 | 12 | if ($data = $cache->get($_SERVER['REQUEST_URI'])) { 13 | print $data; 14 | die(); 15 | } 16 | 17 | ob_start(); 18 | 19 | $timer = new Benchmark_Timer(true); 20 | $timer->start(); 21 | 22 | require_once 'Google/Maps.php'; 23 | $map = Google_Maps::create('static'); 24 | 25 | $map->setKey(trim(file_get_contents('api_key.txt'))); 26 | $map->setSize('540x300'); 27 | $map->setType('terrain'); 28 | 29 | $zoom = Google_Maps_Control::create('zoom'); 30 | $map->addControl($zoom); 31 | $pan = Google_Maps_Control::create('pan'); 32 | $map->addControl($pan); 33 | 34 | $timer->setMarker('Start loading KML'); 35 | 36 | $xml = simplexml_load_file('cities.kml', null, LIBXML_NOCDATA); 37 | 38 | $timer->setMarker('KML loaded'); 39 | 40 | foreach ($xml->Document->Placemark as $placemark) { 41 | list($longitude, $latitude, $elevation) = explode(',', $placemark->Point->coordinates, 3); 42 | $coordinate = new Google_Maps_Coordinate($latitude, $longitude); 43 | $marker = new Google_Maps_Marker($coordinate); 44 | $marker->setSize('small'); 45 | $marker->setColor('blue'); 46 | /* 47 | $bubble = new Google_Maps_Infowindow($placemark->description); 48 | $bubble->setMarker($marker); 49 | $map->addInfowindow($bubble); 50 | */ 51 | $map->addMarker($marker); 52 | } 53 | 54 | $timer->setMarker('Markers created'); 55 | 56 | $map->zoomToFit(); 57 | 58 | $timer->setMarker('Zoom calculated'); 59 | 60 | $map->setProperties($_GET); 61 | 62 | $clusterer = Google_Maps_Clusterer::create('distance'); 63 | $map->setClusterer($clusterer); 64 | 65 | //$map->getClusteredMarkers('string', $map->getBounds()); 66 | 67 | $timer->setMarker('Clustered'); 68 | 69 | $timer->stop(); 70 | //$timer->display(); 71 | 72 | //print $map->toUrl(); 73 | 74 | 75 | //die(); 76 | ?> 77 | 78 | 79 | 80 | 81 | 82 | Clustered Markers With Static Maps Demo 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |
91 | 92 | 93 | 110 | 111 | 112 | 113 |
114 | 115 | 116 |
117 | 118 |
119 |

Clustered Markers With Static Maps

120 |

There is no JavaScript in this page (except Google Analytics)

121 |
122 |

123 |

124 |
125 | toHtml(); ?> 126 |

127 |

128 | Markers are created from KML. Markers are clustered using 129 | distance based clustering. 130 | Zooming and panning works. There is no JavaScript (except Google Analytics) used in this page. 131 | Map is created using following code: 132 |

133 |

134 |

require_once 'Google/Maps.php';
135 | 
136 | require_once 'Google/Maps.php';
137 | $map = Google_Maps::create('static');
138 | 
139 | $map->setKey(API_KEY);
140 | $map->setSize('540x300');
141 | $map->setType('terrain');
142 | 
143 | $zoom = Google_Maps_Control::create('zoom');
144 | $map->addControl($zoom);
145 | $pan = Google_Maps_Control::create('pan');
146 | $map->addControl($pan);
147 | 
148 | $clusterer = Google_Maps_Clusterer::create('distance');
149 | $map->setClusterer($clusterer);
150 | 
151 | $xml = simplexml_load_file('cities.kml', null, LIBXML_NOCDATA);
152 | 
153 | foreach ($xml->Document->Placemark as $placemark) {
154 |     list($longitude, $latitude, $elevation) = 
155 |         explode(',', $placemark->Point->coordinates, 3);
156 |     $coordinate = new Google_Maps_Coordinate($latitude, $longitude);
157 |     $marker = new Google_Maps_Marker($coordinate);
158 |     $marker->setSize('small');
159 |     $marker->setColor('blue');
160 | }
161 | 
162 | $map->zoomToFit();
163 | $map->setProperties($_GET);
164 | 165 |

Where's the Source?

166 |

167 | Code uses work in progress Simple Static Maps PHP class. 168 | It aims to make working with static maps jolly good. Code is still alpha quality. 169 | API might change any time. Use at your own risk. 170 |

171 |

172 | If you like this you might also want to see walkthrough and other features. 173 |

174 | 175 |
176 |
177 | 178 |
179 | 180 |
181 | 182 | 183 | 184 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 198 | 199 | 200 | 201 | save($data); 204 | ?> 205 | 206 | -------------------------------------------------------------------------------- /controls.html: -------------------------------------------------------------------------------- 1 | setKey(trim(file_get_contents('api_key.txt'))); 7 | $map->setSize('540x300'); 8 | 9 | $coord_1 = new Google_Maps_Coordinate('58.378700', '26.731110'); 10 | $coord_2 = new Google_Maps_Coordinate('58.379646', '26.764090'); 11 | 12 | $marker_1 = new Google_Maps_Marker($coord_1); 13 | $marker_2 = new Google_Maps_Marker($coord_2); 14 | 15 | $map->addMarker($marker_1); 16 | $map->addMarker($marker_2); 17 | $map->zoomToFit(); 18 | 19 | $zoom = Google_Maps_Control::create('zoom'); 20 | $map->addControl($zoom); 21 | $pan = Google_Maps_Control::create('pan'); 22 | $map->addControl($pan); 23 | 24 | $bubble_1 = new Google_Maps_Infowindow('Foo Bar'); 25 | $bubble_2 = new Google_Maps_Infowindow('Pler pop'); 26 | 27 | $bubble_1->setMarker($marker_1); 28 | $bubble_2->setMarker($marker_2); 29 | 30 | $map->addInfowindow($bubble_1); 31 | $map->addInfowindow($bubble_2); 32 | 33 | $map->setProperties($_GET); 34 | 35 | ?> 36 | 37 | 38 | 39 | 40 | 41 | Static Map Controls and Infowindow Demo 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 69 | 70 | 71 | 72 |
73 | 74 | 75 |
76 | 77 |
78 |

Add Controls and Infowindow to Static Map

79 |

There is no JavaScript in this page (except Google Analytics)

80 |
81 |
82 | toHtml(); ?> 83 |

84 |

85 | Try to click markers and zoom or pan. There is no JavaScript (except Google Analytics) 86 | used in this page. Above map is created using code below. 87 |

88 |

89 |

require_once 'Google/Maps.php';
 90 | 
 91 | $map = Google_Maps::create('static');
 92 | 
 93 | $map->setKey(API_KEY);
 94 | $map->setSize('540x300');
 95 | 
 96 | $coord_1 = new Google_Maps_Coordinate('58.378700', '26.731110');
 97 | $coord_2 = new Google_Maps_Coordinate('58.379646', '26.764090');
 98 | 
 99 | $marker_1 = new Google_Maps_Marker($coord_1);
100 | $marker_2 = new Google_Maps_Marker($coord_2);
101 | 
102 | $map->addMarker($marker_1);
103 | $map->addMarker($marker_2);
104 | $map->zoomToFit();
105 | 
106 | $zoom = Google_Maps_Control::create('zoom');
107 | $map->addControl($zoom);
108 | $pan = Google_Maps_Control::create('pan');
109 | $map->addControl($pan);
110 | 
111 | $bubble_1 = new Google_Maps_Infowindow('Foo Bar');
112 | $bubble_2 = new Google_Maps_Infowindow('Pler pop');
113 | 
114 | $bubble_1->setMarker($marker_1);
115 | $bubble_2->setMarker($marker_2);
116 | 
117 | $map->addInfowindow($bubble_1);
118 | $map->addInfowindow($bubble_2);
119 | 
120 | $map->setProperties($_GET);
121 | 122 |

Where's the Source?

123 |

124 | Code uses work in progress Simple Static Maps PHP class. 125 | It aims to make working with static maps jolly good. Code is still alpha quality. 126 | API might change any time. Use at your own risk. 127 |

128 |

129 | If you like this you might also want to see walkthrough and other features. 130 |

131 | 132 |
133 |
134 | 135 |
136 | 137 |
138 | 139 | 140 | 141 | 145 | 146 | 147 |
148 | 149 | 150 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /css/controls.css: -------------------------------------------------------------------------------- 1 | /* @override http://127.0.0.1/~tuupola/php/Google_Maps/css/controls.css */ 2 | 3 | /* Google controls */ 4 | 5 | #map img { 6 | float: left; 7 | } 8 | 9 | #controls { 10 | width: 37px; 11 | height: 94px; 12 | position: relative; 13 | left: 7px; 14 | top: 7px; 15 | } 16 | 17 | #controls img { 18 | border: none; 19 | clear: none; 20 | } 21 | 22 | #pan_north { 23 | position: absolute; 24 | left: 9px; 25 | top: 0px; 26 | width: 18px; 27 | height: 18px; 28 | } 29 | 30 | #pan_south { 31 | position: absolute; 32 | left: 9px; 33 | top: 36px; 34 | width: 18px; 35 | height: 18px; 36 | } 37 | 38 | #pan_west { 39 | position: absolute; 40 | left: 0px; 41 | top: 18px; 42 | width: 18px; 43 | height: 18px; 44 | } 45 | 46 | #pan_east { 47 | position: absolute; 48 | left: 18px; 49 | top: 18px; 50 | width: 18px; 51 | height: 18px; 52 | } 53 | 54 | #zoom_in { 55 | position: absolute; 56 | left: 9px; 57 | top: 57px; 58 | width: 18px; 59 | height: 18px; 60 | } 61 | 62 | #zoom_out { 63 | position: absolute; 64 | left: 9px; 65 | top: 75px; 66 | width: 18px; 67 | height: 18px; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /css/infowindow.css: -------------------------------------------------------------------------------- 1 | /* Stylesheet for Google Map infowindow. Generated with FireBug. */ 2 | 3 | div.bubble-top-right, 4 | div.bubble-top-left, 5 | div.bubble-pointer, 6 | div.bubble-bottom-left, 7 | div.bubble-bottom-right, 8 | div.bubble-border-top, 9 | div.bubble-border-bottom, 10 | div.bubble-border-left-right, 11 | div.bubble-content { 12 | overflow: hidden; 13 | width: 25px; 14 | height: 25px; 15 | z-index: 1; 16 | position: absolute; 17 | } 18 | 19 | img.bubble-close, 20 | img.bubble-top-right, 21 | img.bubble-top-left, 22 | img.bubble-pointer, 23 | img.bubble-bottom-left, 24 | img.bubble-bottom-right, 25 | img.bubble-border-top, 26 | img.bubble-border-bottom, 27 | img.bubble-border-left-right { 28 | border: 0px none !important; 29 | margin: 0px !important; 30 | padding: 0px !important; 31 | position: absolute !important; 32 | width: 690px; 33 | height: 786px; 34 | } 35 | 36 | div.bubble-top-right { 37 | left: 378px; 38 | top: 0px; 39 | } 40 | 41 | img.bubble-top-right { 42 | position: absolute; 43 | left: -665px; 44 | top: 0px; 45 | } 46 | 47 | div.bubble-top-left { 48 | left: 0px; 49 | top: 0px; 50 | } 51 | 52 | img.bubble-top-left { 53 | left: 0px; 54 | top: 0px; 55 | } 56 | 57 | div.bubble-pointer { 58 | width: 98px; 59 | height: 96px; 60 | left: 153px; 61 | top: 98px; 62 | z-index: 2; 63 | } 64 | 65 | img.bubble-pointer { 66 | left: 0px; 67 | top: -690px; 68 | } 69 | 70 | div.bubble-bottom-left { 71 | left: 0px; 72 | top: 98px; 73 | } 74 | 75 | img.bubble-bottom-left { 76 | left: 0px; 77 | top: -665px; 78 | } 79 | 80 | div.bubble-bottom-right { 81 | left: 378px; 82 | top: 98px; 83 | } 84 | 85 | img.bubble-bottom-right { 86 | left: -665px; 87 | top: -665px; 88 | } 89 | 90 | div.bubble-border-top { 91 | border-top: 1px solid rgb(171, 171, 171); 92 | left: 25px; 93 | top: 0px; 94 | width: 353px; 95 | height: 24px; 96 | background-color: white; 97 | } 98 | 99 | div.bubble-border-bottom { 100 | border-bottom: 1px solid rgb(171, 171, 171); 101 | left: 25px; 102 | top: 98px; 103 | width: 353px; 104 | height: 24px; 105 | background-color: white; 106 | } 107 | 108 | div.bubble-border-left-right { 109 | border-left: 1px solid rgb(171, 171, 171); 110 | border-right: 1px solid rgb(171, 171, 171); 111 | left: 0px; top: 25px; 112 | width: 401px; 113 | height: 73px; 114 | background-color: white; 115 | } 116 | 117 | div.bubble-content { 118 | overflow: auto; 119 | left: 16px; 120 | top: 16px; 121 | width: 371px; 122 | height: 91px; 123 | z-index: 10; 124 | } 125 | 126 | div.bubble-content img { 127 | margin-right: 10px !important; 128 | } 129 | 130 | img.bubble-close { 131 | border: 0px none; 132 | margin: 0px; 133 | padding: 0px; 134 | position: absolute; 135 | left: 379px; 136 | top: 11px; 137 | width: 12px; 138 | height: 12px; 139 | cursor: pointer; 140 | z-index: 10000; 141 | } 142 | -------------------------------------------------------------------------------- /kml.html: -------------------------------------------------------------------------------- 1 | get($_SERVER['REQUEST_URI'])) { 8 | print $data; 9 | die(); 10 | } 11 | 12 | ob_start(); 13 | 14 | require_once 'Google/Maps.php'; 15 | $map = Google_Maps::create('static'); 16 | 17 | $map->setKey(trim(file_get_contents('api_key.txt'))); 18 | $map->setSize('540x300'); 19 | 20 | $zoom = Google_Maps_Control::create('zoom'); 21 | $map->addControl($zoom); 22 | $pan = Google_Maps_Control::create('pan'); 23 | $map->addControl($pan); 24 | 25 | $clusterer = Google_Maps_Clusterer::create('distance'); 26 | $map->setClusterer($clusterer); 27 | 28 | $xml = simplexml_load_file('http://kaskoabi.ergoaitab.ee/ergo2.kml', null, LIBXML_NOCDATA); 29 | 30 | foreach ($xml->Document->Placemark as $placemark) { 31 | list($longitude, $latitude, $elevation) = explode(',', $placemark->Point->coordinates, 3); 32 | $coordinate = new Google_Maps_Coordinate($latitude, $longitude); 33 | $marker = new Google_Maps_Marker($coordinate); 34 | $marker->setSize('small'); 35 | $marker->setColor('blue'); 36 | $bubble = new Google_Maps_Infowindow($placemark->description); 37 | $bubble->setMarker($marker); 38 | $map->addMarker($marker); 39 | $map->addInfowindow($bubble); 40 | } 41 | 42 | $map->zoomToFit(); 43 | 44 | $map->setProperties($_GET); 45 | 46 | ?> 47 | 48 | 49 | 50 | 51 | 52 | Static Map With KML Data Demo 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
61 | 62 | 63 | 80 | 81 | 82 | 83 |
84 | 85 | 86 |
87 | 88 |
89 |

KML Data With Static Maps

90 |

There is no JavaScript in this page (except Google Analytics)

91 |
92 |
93 | toHtml(); ?> 94 |

95 |

96 | Markers and infowindow data comes from KML. 97 | Zooming and panning works. There is noJavaScript (except Google Analytics) used in this page. 98 | Markers are clustered using distance based clustering. 99 | Map is created using following code: 100 |

101 |

102 |

require_once 'Google/Maps.php';
103 | 
104 | $map = Google_Maps::create('static');
105 | 
106 | $map->setKey(API_KEY);
107 | $map->setSize('540x300');
108 | 
109 | $zoom = Google_Maps_Control::create('zoom');
110 | $map->addControl($zoom);
111 | $pan = Google_Maps_Control::create('pan');
112 | $map->addControl($pan);
113 | 
114 | $clusterer = Google_Maps_Clusterer::create('distance');
115 | $map->setClusterer($clusterer);
116 | 
117 | $xml = simplexml_load_file('http://kaskoabi.ergoaitab.ee/ergo2.kml', 
118 |                             null, LIBXML_NOCDATA);
119 | 
120 | foreach ($xml->Document->Placemark as $placemark) {
121 |     list($longitude, $latitude, $elevation) = 
122 |          explode(',', $placemark->Point->coordinates, 3);
123 |     $coordinate = new Google_Maps_Coordinate($latitude, $longitude);
124 |     $marker = new Google_Maps_Marker($coordinate);
125 |     $marker->setSize('small');
126 |     $marker->setColor('blue');
127 |     $bubble = new Google_Maps_Infowindow($placemark->description);
128 |     $bubble->setMarker($marker);
129 |     $map->addMarker($marker);
130 |     $map->addInfowindow($bubble);
131 | }
132 | 
133 | $map->zoomToFit();
134 | $map->setProperties($_GET);
135 | 136 |

Where's the Source?

137 |

138 | Code uses work in progress Simple Static Maps PHP class. 139 | It aims to make working with static maps jolly good. Code is still alpha quality. 140 | API might change any time. Use at your own risk. 141 |

142 |

143 | If you like this you might also want to see walkthrough and other features. 144 |

145 | 146 |
147 |
148 | 149 |
150 | 151 |
152 | 153 | 154 | 155 | 159 | 160 | 161 |
162 | 163 | 164 | 176 | 177 | 178 | 179 | 183 | 184 | 185 | 186 | 187 | save($data); 190 | ?> 191 | -------------------------------------------------------------------------------- /tests/01_lattoy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Mercator::LonToX() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 17 | --GET-- 18 | --POST-- 19 | --EXPECT-- 20 | 230704001 21 | 0 22 | 268435456 23 | 536870912 24 | -------------------------------------------------------------------------------- /tests/02_lontox.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Mercator::LonToX() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 17 | --GET-- 18 | --POST-- 19 | --EXPECT-- 20 | 355500011 21 | 268435456 22 | 0 23 | 536870912 24 | 25 | -------------------------------------------------------------------------------- /tests/03_xtolon.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Mercator::LonToX() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 17 | --GET-- 18 | --POST-- 19 | --EXPECT-- 20 | 58.3813335747 21 | 0 22 | -180 23 | 180 -------------------------------------------------------------------------------- /tests/04_ytolat.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Mercator::LonToX() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 16 | --GET-- 17 | --POST-- 18 | --EXPECT-- 19 | 24.5165921956 20 | 85.0511287798 21 | -85.0511287798 22 | -------------------------------------------------------------------------------- /tests/05_bounds.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Bounds::create() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getNorthWest()); 18 | print_r($bounds_1->getSouthEast('point')); 19 | 20 | $coord_1 = new Google_Maps_Coordinate(-85.0511287798, 180); 21 | $coord_2 = new Google_Maps_Coordinate(85.0511287798, -180); 22 | $coord_3 = new Google_Maps_Coordinate(24.5165921956, 58.3813335747); 23 | 24 | $bounds_2 = new Google_Maps_Bounds(array($coord_1, $coord_2, $coord_3)); 25 | 26 | print_r($bounds_2->getNorthWest()); 27 | print_r($bounds_2->getSouthEast('point')); 28 | 29 | 30 | ?> 31 | --GET-- 32 | --POST-- 33 | --EXPECT-- 34 | Google_Maps_Coordinate Object 35 | ( 36 | [lat:protected] => 85.0511287798 37 | [lon:protected] => -180 38 | ) 39 | Google_Maps_Point Object 40 | ( 41 | [x:protected] => 536870912 42 | [y:protected] => 536870912 43 | ) 44 | Google_Maps_Coordinate Object 45 | ( 46 | [lat:protected] => 85.0511287798 47 | [lon:protected] => -180 48 | ) 49 | Google_Maps_Point Object 50 | ( 51 | [x:protected] => 536870912 52 | [y:protected] => 536870912 53 | ) -------------------------------------------------------------------------------- /tests/06_point.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Point 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | toCoordinate()); 16 | print_r($point_2->toCoordinate()); 17 | print_r($point_3->toCoordinate()); 18 | 19 | ?> 20 | --GET-- 21 | --POST-- 22 | --EXPECT-- 23 | Google_Maps_Coordinate Object 24 | ( 25 | [lat:protected] => 85.0511287798 26 | [lon:protected] => -180 27 | ) 28 | Google_Maps_Coordinate Object 29 | ( 30 | [lat:protected] => -85.0511287798 31 | [lon:protected] => 180 32 | ) 33 | Google_Maps_Coordinate Object 34 | ( 35 | [lat:protected] => 24.5165921956 36 | [lon:protected] => 58.3813335747 37 | ) 38 | -------------------------------------------------------------------------------- /tests/07_coordinate.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Coordinate 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | toPoint()); 16 | print_r($coord_2->toPoint()); 17 | print_r($coord_3->toPoint()); 18 | 19 | ?> 20 | --GET-- 21 | --POST-- 22 | --EXPECT-- 23 | Google_Maps_Point Object 24 | ( 25 | [x:protected] => 536870912 26 | [y:protected] => 536870912 27 | ) 28 | Google_Maps_Point Object 29 | ( 30 | [x:protected] => 0 31 | [y:protected] => 0 32 | ) 33 | Google_Maps_Point Object 34 | ( 35 | [x:protected] => 355500011 36 | [y:protected] => 230704001 37 | ) 38 | -------------------------------------------------------------------------------- /tests/08_maps_factory.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps::create() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 21 | --GET-- 22 | --POST-- 23 | --EXPECT-- 24 | Google_Maps_Static 25 | -------------------------------------------------------------------------------- /tests/09_bounds_contains.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Bounds::create() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | contains($point_3)); 29 | print "\n2 (true) - "; 30 | print_r($bounds_1->contains($coord_3)); 31 | 32 | print "\n3 (false)- "; 33 | print_r($bounds_2->contains($point_3)); 34 | print "\n4 (false) - "; 35 | print_r($bounds_2->contains($coord_3)); 36 | 37 | print "\n5 (true) - "; 38 | print_r($bounds_3->contains($point_3)); 39 | print "\n6 (true) - "; 40 | print_r($bounds_3->contains($coord_3)); 41 | 42 | print "\n7 (false) - "; 43 | print_r($bounds_4->contains($point_3)); 44 | print "\n8 (false) - "; 45 | print_r($bounds_4->contains($coord_3)); 46 | 47 | 48 | ?> 49 | --GET-- 50 | --POST-- 51 | --EXPECT-- 52 | 1 (true) - 1 53 | 2 (true) - 1 54 | 3 (false)- 55 | 4 (false) - 56 | 5 (true) - 1 57 | 6 (true) - 1 58 | 7 (false) - 59 | 8 (false) - 60 | -------------------------------------------------------------------------------- /tests/10_marker.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps_Marker 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getCoordinate()); 17 | print $marker->getLat(); 18 | print "\n"; 19 | print $marker->getLon(); 20 | print "\n"; 21 | print $marker->getColor(); 22 | 23 | ?> 24 | --GET-- 25 | --POST-- 26 | --EXPECT-- 27 | Google_Maps_Coordinate Object 28 | ( 29 | [lat:protected] => 24.5165921956 30 | [lon:protected] => 58.3813335747 31 | ) 32 | 24.5165921956 33 | 58.3813335747 34 | blue 35 | 36 | -------------------------------------------------------------------------------- /tests/11_maps_setcenter.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Google_Maps::create() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | setCenter($coord); 20 | $map_2->setCenter($point); 21 | $map_3->setCenter("24.5165921956, 58.3813335747"); 22 | 23 | print_r($map_1->getCenter()); 24 | print_r($map_2->getCenter()); 25 | print_r($map_3->getCenter()); 26 | 27 | ?> 28 | --GET-- 29 | --POST-- 30 | --EXPECT-- 31 | Google_Maps_Coordinate Object 32 | ( 33 | [lat:protected] => 24.5165921956 34 | [lon:protected] => 58.3813335747 35 | ) 36 | Google_Maps_Coordinate Object 37 | ( 38 | [lat:protected] => 24.5165921956 39 | [lon:protected] => 58.3813335747 40 | ) 41 | Google_Maps_Coordinate Object 42 | ( 43 | [lat:protected] => 24.5165921956 44 | [lon:protected] => 58.3813335747 45 | ) -------------------------------------------------------------------------------- /tests/skipif.php: -------------------------------------------------------------------------------- 1 |