├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml └── src └── GeneaLabs └── Phpgmaps ├── Facades └── PhpgmapsFacade.php ├── Phpgmaps.php └── PhpgmapsServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | /.idea 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | - 5.6 8 | - hhvm 9 | 10 | before_script: 11 | - composer self-update 12 | - composer install --prefer-source --no-interaction --dev 13 | 14 | script: phpunit 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | ## [0.3.8 - 0.3.9] - 2016-08-07 3 | ### Added 4 | - automatic setting of apiKey from `config('services.google.maps.api-key')`. 5 | 6 | ### Removed 7 | - deprectated 'sensor' querystring parameter, which would trigger a "SensorNotRequired" warning. 8 | 9 | ## [0.3.5 - 0.3.7] - 2016-01-11 10 | ### Added 11 | - clusterstyles (thanks to @MichaelGollinski). 12 | 13 | ### Changed 14 | - script tag 'src' attributes to always referr to 'https' targets. 15 | 16 | ### Removed 17 | - options to manually choose http or https. 18 | 19 | ## [0.3.4] - 2015-12-11 20 | ### Fixed 21 | - class name conflicts. 22 | 23 | ### Removed 24 | - auto-loading of Facade to avoid conflicts. 25 | 26 | ## 0.3.0 - 0.3.3: 25 Jun 2015 27 | ### Added 28 | - License 29 | - Change Log 30 | 31 | ### Changed 32 | - Namespace from Appitventures to GeneaLabs. 33 | - Installation instructions, affected areas of README. 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 BIOSTALL, AppItVentures, GeneaLabs. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This package has moved! 2 | https://github.com/GeneaLabs/laravel-maps 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genealabs/phpgmaps", 3 | "description": "Laravel implementation of BIOSTALL's CodeIgniter Google Maps API, originally by Michael Hopkins at Appitventures.", 4 | "license": "MIT", 5 | "keywords": [ 6 | "laravel", 7 | "phpgmaps", 8 | "googlemaps", 9 | "biostall" 10 | ], 11 | "authors": [ 12 | { 13 | "name": "Mike Bronner", 14 | "email": "mike@genealabs.com", 15 | "role": "maintainer" 16 | }, 17 | { 18 | "name": "Michael Hopkins", 19 | "role": "developer" 20 | } 21 | ], 22 | "require": { 23 | "php": ">=5.4.0", 24 | "laravel/framework": "5.*" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "GeneaLabs\\Phpgmaps\\": "src/GeneaLabs/Phpgmaps/" 29 | } 30 | }, 31 | "extra": { 32 | "branch-alias": { 33 | "dev-laravel4": "1.0-dev", 34 | "dev-develop": "2.0-dev", 35 | "dev-master": "2.0-dev" 36 | } 37 | }, 38 | "minimum-stability": "stable" 39 | } 40 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/GeneaLabs/Phpgmaps/Facades/PhpgmapsFacade.php: -------------------------------------------------------------------------------- 1 | section. The library will try to create the file if it does not exist already. Please ensure the destination file is writeable 43 | public $kmlLayerURL = ''; // A URL to publicly available KML or GeoRSS data for displaying geographic information. Multiple KML layers can be passed in by using an array of URL's. Note, if using multiple you'll probably have to set $kmlLayerPreserveViewport to true and manually set map center and zoom 44 | public $kmlLayerPreserveViewport = false; // Specifies whether the map should be adjusted to the bounds of the KmlLayer's contents. By default the map is zoomed and positioned to show the entirety of the layer's contents 45 | public $language = ''; // The map will by default load in the language of the browser. This can be overriden however here. For a full list of codes see https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1 46 | public $loadAsynchronously = false; // Load the map and API asynchronously once the page has loaded 47 | public $map_div_id = "map_canvas"; // The ID of the
that is output which contains the map 48 | public $map_height = "450px"; // The height of the map container. Any units (ie 'px') can be used. If no units are provided 'px' will be presumed 49 | public $map_name = "map"; // The JS reference to the map. Currently not used but to be used in the future when multiple maps are supported 50 | public $map_type = "ROADMAP"; // The default MapType. Values accepted are 'HYBRID', 'ROADMAP', 'SATELLITE' or 'TERRAIN' 51 | public $map_types_available = array(); // The other MapTypes available for selection on the map 52 | public $map_width = "100%"; // The width of the map container. Any units (ie 'px') can be used. If no units are provided 'px' will be presumed 53 | public $maps_loaded = 0; // Counter which keeps track of how many maps have been created to avoid standard functions being output twice 54 | public $mapTypeControlPosition = ''; // The position of the MapType control, eg. 'BOTTOM_RIGHT' 55 | public $mapTypeControlStyle = ''; // The style of the MapType control. blank, 'DROPDOWN_MENU' or 'HORIZONTAL_BAR' values accepted. 56 | public $minzoom = ''; // The minimum zoom level which will be displayed on the map 57 | public $maxzoom = ''; // The maximum zoom level which will be displayed on the map 58 | public $minifyJS = false; // If TRUE will run the JavaScript through Jsmin.php (this file and PHP5+ required) to minify the code 59 | public $noClear = false; // If TRUE do not clear the contents of the map div 60 | public $onboundschanged = ''; // The JavaScript action to perform when the viewport bounds have changed 61 | public $oncenterchanged = ''; // The JavaScript action to perform when themap center property changes 62 | public $onclick = ''; // The JavaScript action to perform when the map is clicked 63 | public $ondblclick = ''; // The JavaScript action to perform when the map is double-clicked 64 | public $ondrag = ''; // The JavaScript action to perform while the map is dragged 65 | public $ondragend = ''; // The JavaScript action to perform when the user stops dragging the map 66 | public $ondragstart = ''; // The JavaScript action to perform when the user starts dragging the map 67 | public $onidle = ''; // The JavaScript action to perform when the map becomes idle after panning or zooming 68 | public $onload = ''; // The JavaScript action to perform when the map first loads. This library hi-jacks the window.load event so add any bespoke code using this option 69 | public $onmousemove = ''; // The JavaScript action to perform when the user's mouse moves over the map container 70 | public $onmouseout = ''; // The JavaScript action to perform when the user's mouse exits the map container 71 | public $onmouseover = ''; // The JavaScript action to perform when the user's mouse enters the map container 72 | public $onresize = ''; // The JavaScript action to perform when the maps div changes size 73 | public $onrightclick = ''; // The JavaScript action to perform when the map is right-clicked 74 | public $ontilesloaded = ''; // The JavaScript action to perform when the visible tiles have finished loading 75 | public $onzoomchanged = ''; // The JavaScript action to perform when the maps zoom property changes 76 | public $panoramio = false; // If TRUE will add photos from Panoramio as a layer to your maps as a series of large and small photo icons 77 | public $panoramioTag = ''; // Restrict the set of Panoramio photos shown to those matching a certain textual tag 78 | public $panoramioUser = ''; // Restrict the set of Panoramio photos shown to those matching a particular user 79 | public $region = ''; // Country code top-level domain (eg "uk") within which to search. Useful if supplying addresses rather than lat/longs 80 | public $scaleControlPosition = ''; // The position of the Scale control, eg. 'BOTTOM_RIGHT' 81 | public $scrollwheel = true; // If set to FALSE will disable zooming by scrolling of the mouse wheel 82 | public $streetViewAddressControl = true; // If set to FALSE will hide the Address control 83 | public $streetViewAddressPosition = ''; // The position of the Address control, eg. 'BOTTOM' 84 | public $streetViewControlPosition = ''; // The position of the Street View control when viewing normal aerial map, eg. 'BOTTOM_RIGHT' 85 | public $streetViewCloseButton = false; // If set to TRUE will show the close button in the top right. The close button allows users to return to the aerial map 86 | public $streetViewLinksControl = true; // If set to FALSE will hide the Links control 87 | public $streetViewPanControl = true; // If set to FALSE will hide the Pan control 88 | public $streetViewPanPosition = ''; // The position of the Scale control, eg. 'TOP_RIGHT' 89 | public $streetViewPovHeading = 0; // The Street View camera heading in degrees relative to true north. True north is 0, east is 90, south is 180, west is 270 90 | public $streetViewPovPitch = 0; // The Street View camera pitch in degrees, relative to the street view vehicle. Directly upwards is 90, Directly downwards is -90. 91 | public $streetViewPovZoom = 0; // The Street View zoom level. Fully zoomed-out is level 0, zooming in increases the zoom level. 92 | public $streetViewZoomControl = true; // If set to FALSE will hide the Zoom control 93 | public $streetViewZoomPosition = ''; // The position of the Scale control, eg. 'TOP_RIGHT' 94 | public $streetViewZoomStyle = ''; // The size of the Street View zoom control. blank, 'SMALL' or 'LARGE' values accepted. 95 | public $styles = array(); // An array of styles used to colour aspects of the map and turn points of interest on and off 96 | public $stylesAsMapTypes = false; // If applying styles, whether to apply them to the default map or add them as additional map types 97 | public $stylesAsMapTypesDefault = ''; // If $stylesAsMapTypes is true the default style. Should contain the 'Name' of the style 98 | public $tilt = 0; // The angle of tilt. Currently only supports the values 0 and 45 in SATELLITE and HYBRID map types and at certain zoom levels 99 | public $trafficOverlay = false; // If set to TRUE will overlay traffic information onto the map by default 100 | public $version = "3"; // Version of the API being used. Not currently used in the library 101 | public $zoom = 13; // The default zoom level of the map. If set to "auto" will autozoom/center to fit in all visible markers. If "auto", also overrides the $center parameter 102 | public $zoomControlPosition = ''; // The position of the Zoom control, eg. 'BOTTOM_RIGHT' 103 | public $zoomControlStyle = ''; // The size of the zoom control. blank, 'SMALL' or 'LARGE' values accepted. 104 | 105 | public $markers = array(); // An array used by the library to store the markers as they are produced 106 | public $markersInfo = array(); // An array containing marker information (id, latitude, longitude etc) for use elsewhere 107 | public $polylines = array(); // An array used by the library to store the polylines as they are produced 108 | public $polygons = array(); // An array used by the library to store the polygons as they are produced 109 | public $circles = array(); // An array used by the library to store the circles as they are produced 110 | public $rectangles = array(); // An array used by the library to store the rectangles as they are produced 111 | public $overlays = array(); // An array used by the library to store the overlays as they are produced 112 | 113 | public $directions = false; // Whether or not the map will be used to show directions 114 | public $directionsStart = ""; // The starting location (lat/long co-ordinate or address) of the directions. Set to 'auto' to default it to the users location 115 | public $directionsEnd = ""; // The destination point (lat/long co-ordinate or address) of the directions. Set to 'auto' to default it to the users location 116 | public $directionsDivID = ""; // An element's ID on the page where textual directions will be output to. Leave blank if not required 117 | public $directionsMode = "DRIVING"; // DRIVING, WALKING or BICYCLING (US Only) - The vehicle/mode of transport to show directions for 118 | public $directionsAvoidTolls = false; // Whether or not directions should avoid tolls 119 | public $directionsAvoidHighways = false; // Whether or not directions should avoid highways 120 | public $directionsDraggable = false; // Whether or not directions on the map are draggable 121 | public $directionsChanged = ""; // JavaScript to perform when directions are dragged 122 | public $directionsUnits = ""; // 'metric' for kilometers and meters or 'imperial for miles and feet. Leave blank and it will default to the region or country of where directions are being obtained 123 | public $directionsWaypointArray = array(); // An array of waypoints. eg array("Boston, MA", "Times Square, NY"); 124 | public $directionsWaypointsOptimize = false; // Should the waypoints be optimised? If TRUE, waypoints will be re-ordered to provide the most efficient route. 125 | 126 | public $drawing = false; // Whether or not the drawing library tools will be loaded 127 | public $drawingControl = true; // If set to FALSE will hide the Drawing Manager control 128 | public $drawingControlPosition = 'TOP_CENTER'; // The position of the Drawing Manager control, eg. 'TOP_RIGHT' 129 | public $drawingDefaultMode = 'marker'; // The default mode for the Drawing Manager. Accepted values are marker, polygon, polyline, rectangle, circle, or null. null means that the user can interact with the map as normal when the map loads, and clicks do not draw anything. 130 | public $drawingModes = array(); // An array of modes available for use. Accepted values are marker, polygon, polyline, rectangle, circle 131 | public $drawingOnComplete = array(); // An array of JS to execute when shapes are completed, one array element per shape. For example: array('circle'=>'JS here', 'polygon'=>'JS here'); 132 | public $drawingOnEdit = array(); // An array of JS to execute when shapes are changed/resized, one array element per shape. For example: array('circle'=>'JS here', 'polygon'=>'JS here'); 133 | 134 | public $places = false; // Whether or not the map will be used to show places 135 | public $placesLocation = ''; // A point (lat/long co-ordinate or address) on the map if the search for places is based around a central point 136 | public $placesRadius = 0; // The radius (in meters) if search is based around a central position 137 | public $placesLocationSW = ''; // If preferring to search within bounds the South-West position (latitude/longitude coordinate OR address) 138 | public $placesLocationNE = ''; // If preferring to search within bounds the North-East position (latitude/longitude coordinate OR address) 139 | public $placesTypes = array(); // The types of places to search for. For a list of supported types see http://code.google.com/apis/maps/documentation/places/supported_types.html 140 | public $placesName = ''; // A term to be matched against when searching for places to display on the map 141 | public $placesAutocompleteInputID = ''; // The ID attribute of the textfield that the autocomplete should effect 142 | public $placesAutocompleteTypes = array(); // The types of places for the autocomplete to return. Options can be seen here https://developers.google.com/maps/documentation/javascript/places#places_autocomplete but include 'establishment' to only return business results, '(cities)', or '(regions)' 143 | public $placesAutocompleteBoundSW = ''; // By specifying an area in which to search for Places, the results are biased towards, but not restricted to, Places contained within these bounds. 144 | public $placesAutocompleteBoundNE = ''; // Both South-West (lat/long co-ordinate or address) and North-East (lat/long co-ordinate or address) values are required if wishing to set bounds 145 | public $placesAutocompleteBoundsMap = false; // An alternative to setting the SW and NE bounds is to use the bounds of the current viewport. If set to TRUE, the bounds will be set to the viewport of the visible map, even if dragged or zoomed 146 | public $placesAutocompleteOnChange = ''; // The JavaScript action to perform when a place is selected 147 | public $gestureHandling = 'auto'; // Controls the panning and scrolling behavior of a map when viewed on a mobile device. greedy(allways moves on touch), cooperative(1 finger scroll 2 finger move), none(not pannable or pinchable), auto 148 | 149 | 150 | public function __construct($config = array()) 151 | { 152 | if (count($config) > 0) { 153 | $this->initialize($config); 154 | } 155 | 156 | #Log::info('debug', "Google Maps Class Initialized"); 157 | } 158 | 159 | public function initialize($config = array()) 160 | { 161 | foreach ($config as $key => $val) { 162 | if (isset($this->$key)) { 163 | $this->$key = $val; 164 | } 165 | } 166 | } 167 | 168 | public function add_marker($params = array()) 169 | { 170 | $marker = array(); 171 | $this->markersInfo['marker_'.count($this->markers)] = array(); 172 | 173 | $marker['position'] = ''; // The position (lat/long co-ordinate or address) at which the marker will appear 174 | $marker['infowindow_content'] = ''; // If not blank, creates an infowindow (aka bubble) with the content provided. Can be plain text or HTML 175 | $marker['id'] = ''; // The unique identifier of the marker suffix (ie. marker_yourID). If blank, this will default to marker_X where X is an incremental number 176 | $marker['clickable'] = true; // Defines if the marker is clickable 177 | $marker['cursor'] = ''; // The name or url of the cursor to display on hover 178 | $marker['draggable'] = false; // Defines if the marker is draggable 179 | $marker['flat'] = false; // If set to TRUE will not display a shadow beneath the icon 180 | $marker['icon'] = ''; // The name or url of the icon to use for the marker 181 | $marker['icon_size'] = ''; // The display size of the sprite or image being used. When using sprites, you must specify the sprite size. Expecting two comma-separated values for width and height respectively (ie '20,30'). See https://developers.google.com/maps/documentation/javascript/3.exp/reference#Icon 182 | $marker['icon_scaledSize'] = ''; // The size of the entire image after scaling, if any. Use this property to stretch/shrink an image or a sprite. Expecting two comma-separated values for width and height respectively (ie '20,30') 183 | $marker['icon_origin'] = ''; // If using a sprite, the position of the image within the sprite. Expecting two comma-separated values for distance from the top and left respectively (ie '20,30') 184 | $marker['icon_anchor'] = ''; // The position at which to anchor an image in correspondance to the location of the marker on the map. By default, the anchor is located along the center point of the bottom of the image. Expecting two comma-separated values (ie '20,30'). Credit to https://github.com/colethorsen 185 | $marker['animation'] = ''; // blank, 'DROP' or 'BOUNCE' 186 | $marker['onclick'] = ''; // JavaScript performed when a marker is clicked 187 | $marker['ondblclick'] = ''; // JavaScript performed when a marker is double-clicked 188 | $marker['ondrag'] = ''; // JavaScript repeatedly performed while the marker is being dragged 189 | $marker['ondragstart'] = ''; // JavaScript performed when a marker is started to be dragged 190 | $marker['ondragend'] = ''; // JavaScript performed when a draggable marker is dropped 191 | $marker['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a marker 192 | $marker['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the marker icon 193 | $marker['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the marker icon 194 | $marker['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a marker 195 | $marker['onpositionchanged'] = ''; // JavaScript performed when the markers position changes 196 | $marker['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a marker 197 | $marker['raiseondrag'] = true; // If FALSE, disables the raising and lowering of the icon when a marker is being dragged 198 | $marker['shadow'] = ''; // The name or url of the icon's shadow 199 | $marker['title'] = ''; // The tooltip text to show on hover 200 | $marker['visible'] = true; // Defines if the marker is visible by default 201 | $marker['zIndex'] = ''; // The zIndex of the marker. If two markers overlap, the marker with the higher zIndex will appear on top 202 | $marker['label'] = ''; // The label of the marker. 203 | 204 | $marker_output = ''; 205 | 206 | foreach ($params as $key => $value) { 207 | if (isset($marker[$key])) { 208 | $marker[$key] = $value; 209 | } 210 | } 211 | 212 | $marker_id = count($this->markers); 213 | if (trim($marker['id']) != "") { 214 | $marker_id = $marker['id']; 215 | } 216 | 217 | if ($marker['position'] != "") { 218 | if ($this->is_lat_long($marker['position'])) { 219 | $marker_output .= ' 220 | var myLatlng = new google.maps.LatLng('.$marker['position'].'); 221 | '; 222 | $explodePosition = explode(",", $marker['position']); 223 | $this->markersInfo['marker_'.$marker_id]['latitude'] = trim($explodePosition[0]); 224 | $this->markersInfo['marker_'.$marker_id]['longitude'] = trim($explodePosition[1]); 225 | } else { 226 | $lat_long = $this->get_lat_long_from_address($marker['position']); 227 | $marker_output .= ' 228 | var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');'; 229 | $this->markersInfo['marker_'.$marker_id]['latitude'] = $lat_long[0]; 230 | $this->markersInfo['marker_'.$marker_id]['longitude'] = $lat_long[1]; 231 | } 232 | } 233 | 234 | if ($marker['icon'] != "") { 235 | $marker_output .= ' 236 | var marker_icon = { 237 | url: "'.$marker['icon'].'"'; 238 | if ($marker['icon_size'] != "") { 239 | $marker_output .= ', 240 | size: new google.maps.Size('.$marker['icon_size'].')'; 241 | } 242 | if ($marker['icon_scaledSize'] != "") { 243 | $marker_output .= ', 244 | scaledSize: new google.maps.Size('.$marker['icon_scaledSize'].')'; 245 | } 246 | if ($marker['icon_origin'] != "") { 247 | $marker_output .= ', 248 | origin: new google.maps.Point('.$marker['icon_origin'].')'; 249 | } 250 | if ($marker['icon_anchor'] != "") { 251 | $marker_output .= ', 252 | anchor: new google.maps.Point('.$marker['icon_anchor'].')'; 253 | } 254 | $marker_output .= '}; 255 | '; 256 | } 257 | 258 | $marker_output .= ' 259 | var markerOptions = { 260 | map: '.$this->map_name; 261 | if ($marker['position'] != "") { 262 | $marker_output .= ', 263 | position: myLatlng'; 264 | } 265 | if (!$marker['clickable']) { 266 | $marker_output .= ', 267 | clickable: false'; 268 | } 269 | if ($marker['cursor'] != "") { 270 | $marker_output .= ', 271 | cursor: "'.$marker['cursor'].'"'; 272 | } 273 | if ($marker['draggable']) { 274 | $marker_output .= ', 275 | draggable: true'; 276 | } 277 | if ($marker['flat']) { 278 | $marker_output .= ', 279 | flat: true'; 280 | } 281 | if ($marker['icon'] != "") { 282 | $marker_output .= ', 283 | icon: marker_icon'; 284 | } 285 | if (!$marker['raiseondrag']) { 286 | $marker_output .= ', 287 | raiseOnDrag: false'; 288 | } 289 | if ($marker['shadow'] != "") { 290 | $marker_output .= ', 291 | shadow: "'.$marker['shadow'].'"'; 292 | } 293 | if ($marker['title'] != "") { 294 | $marker_output .= ', 295 | title: "'.$marker['title'].'"'; 296 | $this->markersInfo['marker_'.$marker_id]['title'] = $marker['title']; 297 | } 298 | if (!$marker['visible']) { 299 | $marker_output .= ', 300 | visible: false'; 301 | } 302 | if ($marker['zIndex'] != "" && is_numeric($marker['zIndex'])) { 303 | $marker_output .= ', 304 | zIndex: '.$marker['zIndex']; 305 | } 306 | if ($marker['animation'] != "" && (strtoupper($marker['animation']) == "DROP" || strtoupper($marker['animation'] == "BOUNCE"))) { 307 | $marker_output .= ', 308 | animation: google.maps.Animation.'.strtoupper($marker['animation']); 309 | } 310 | if ($marker['label'] != "") { 311 | $marker_output .= ', 312 | label: "'.$marker['label'].'"'; 313 | } 314 | 315 | 316 | 317 | $marker_output .= ' 318 | }; 319 | marker_'.$marker_id.' = createMarker_'.$this->map_name.'(markerOptions); 320 | '; 321 | 322 | if ($marker['infowindow_content'] != "") { 323 | 324 | // Escape any quotes in the event that HTML is being added to the infowindow 325 | $marker['infowindow_content'] = str_replace('\"', '"', $marker['infowindow_content']); 326 | $marker['infowindow_content'] = str_replace('"', '\"', $marker['infowindow_content']); 327 | 328 | $marker_output .= ' 329 | marker_'.$marker_id.'.set("content", "'.$marker['infowindow_content'].'"); 330 | 331 | google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) { 332 | iw_'.$this->map_name.'.setContent(this.get("content")); 333 | iw_'.$this->map_name.'.open('.$this->map_name.', this); 334 | '; 335 | if ($marker['onclick'] != "") { 336 | $marker_output .= $marker['onclick'].' 337 | '; 338 | } 339 | $marker_output .= ' 340 | }); 341 | '; 342 | } else { 343 | if ($marker['onclick'] != "") { 344 | $marker_output .= ' 345 | google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) { 346 | '.$marker['onclick'].' 347 | }); 348 | '; 349 | } 350 | } 351 | 352 | if ($marker['ondblclick'] != "") { 353 | $marker_output .= ' 354 | google.maps.event.addListener(marker_'.$marker_id.', "dblclick", function(event) { 355 | '.$marker['ondblclick'].' 356 | }); 357 | '; 358 | } 359 | if ($marker['onmousedown'] != "") { 360 | $marker_output .= ' 361 | google.maps.event.addListener(marker_'.$marker_id.', "mousedown", function(event) { 362 | '.$marker['onmousedown'].' 363 | }); 364 | '; 365 | } 366 | if ($marker['onmouseout'] != "") { 367 | $marker_output .= ' 368 | google.maps.event.addListener(marker_'.$marker_id.', "mouseout", function(event) { 369 | '.$marker['onmouseout'].' 370 | }); 371 | '; 372 | } 373 | if ($marker['onmouseover'] != "") { 374 | $marker_output .= ' 375 | google.maps.event.addListener(marker_'.$marker_id.', "mouseover", function(event) { 376 | '.$marker['onmouseover'].' 377 | }); 378 | '; 379 | } 380 | if ($marker['onmouseup'] != "") { 381 | $marker_output .= ' 382 | google.maps.event.addListener(marker_'.$marker_id.', "mouseup", function(event) { 383 | '.$marker['onmouseup'].' 384 | }); 385 | '; 386 | } 387 | if ($marker['onpositionchanged'] != "") { 388 | $marker_output .= ' 389 | google.maps.event.addListener(marker_'.$marker_id.', "position_changed", function(event) { 390 | '.$marker['onpositionchanged'].' 391 | }); 392 | '; 393 | } 394 | if ($marker['onrightclick'] != "") { 395 | $marker_output .= ' 396 | google.maps.event.addListener(marker_'.$marker_id.', "rightclick", function(event) { 397 | '.$marker['onrightclick'].' 398 | }); 399 | '; 400 | } 401 | 402 | if ($marker['draggable']) { 403 | if ($marker['ondrag'] != "") { 404 | $marker_output .= ' 405 | google.maps.event.addListener(marker_'.$marker_id.', "drag", function(event) { 406 | '.$marker['ondrag'].' 407 | }); 408 | '; 409 | } 410 | if ($marker['ondragend'] != "") { 411 | $marker_output .= ' 412 | google.maps.event.addListener(marker_'.$marker_id.', "dragend", function(event) { 413 | '.$marker['ondragend'].' 414 | }); 415 | '; 416 | } 417 | if ($marker['ondragstart'] != "") { 418 | $marker_output .= ' 419 | google.maps.event.addListener(marker_'.$marker_id.', "dragstart", function(event) { 420 | '.$marker['ondragstart'].' 421 | }); 422 | '; 423 | } 424 | } 425 | 426 | array_push($this->markers, $marker_output); 427 | } 428 | 429 | public function add_polyline($params = array()) 430 | { 431 | $polyline = array(); 432 | 433 | $polyline['points'] = array(); // An array of latitude/longitude coordinates OR addresses, or a mixture of both. If an address is supplied the Google geocoding service will be used to return a lat/long. 434 | $polyline['clickable'] = true; // Defines if the polyline is clickable 435 | $polyline['strokeColor'] = '#FF0000'; // The hex value of the polylines color 436 | $polyline['strokeOpacity'] = '1.0'; // The opacity of the polyline. 0 to 1.0 437 | $polyline['strokeWeight'] = '2'; // The thickness of the polyline 438 | $polyline['onclick'] = ''; // JavaScript performed when a polyline is clicked 439 | $polyline['ondblclick'] = ''; // JavaScript performed when a polyline is double-clicked 440 | $polyline['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a polyline 441 | $polyline['onmousemove'] = ''; // JavaScript performed when the mouse moves in the area of the polyline 442 | $polyline['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the polyline 443 | $polyline['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the polyline 444 | $polyline['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a polyline 445 | $polyline['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a polyline 446 | $polyline['zIndex'] = ''; // The zIndex of the polyline. If two polylines overlap, the polyline with the higher zIndex will appear on top 447 | 448 | $polyline_output = ''; 449 | 450 | foreach ($params as $key => $value) { 451 | if (isset($polyline[$key])) { 452 | $polyline[$key] = $value; 453 | } 454 | } 455 | 456 | if (count($polyline['points'])) { 457 | $polyline_output .= ' 458 | var polyline_plan_'.count($this->polylines).' = ['; 459 | $i = 0; 460 | $lat_long_output = ''; 461 | foreach ($polyline['points'] as $point) { 462 | if ($i > 0) { 463 | $polyline_output .= ','; 464 | } 465 | $lat_long_to_push = ''; 466 | if ($this->is_lat_long($point)) { 467 | $lat_long_to_push = $point; 468 | $polyline_output .= ' 469 | new google.maps.LatLng('.$point.') 470 | '; 471 | } else { 472 | $lat_long = $this->get_lat_long_from_address($point); 473 | $polyline_output .= ' 474 | new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')'; 475 | $lat_long_to_push = $lat_long[0].', '.$lat_long[1]; 476 | } 477 | $lat_long_output .= ' 478 | lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.')); 479 | '; 480 | $i++; 481 | } 482 | $polyline_output .= '];'; 483 | 484 | $polyline_output .= $lat_long_output; 485 | 486 | $polyline_output .= ' 487 | var polyline_'.count($this->polylines).' = new google.maps.Polyline({ 488 | path: polyline_plan_'.count($this->polylines).', 489 | strokeColor: "'.$polyline['strokeColor'].'", 490 | strokeOpacity: '.$polyline['strokeOpacity'].', 491 | strokeWeight: '.$polyline['strokeWeight']; 492 | if (!$polyline['clickable']) { 493 | $polyline_output .= ', 494 | clickable: false'; 495 | } 496 | if ($polyline['zIndex'] != "" && is_numeric($polyline['zIndex'])) { 497 | $polyline_output .= ', 498 | zIndex: '.$polyline['zIndex']; 499 | } 500 | $polyline_output .= ' 501 | }); 502 | 503 | polyline_'.count($this->polylines).'.setMap('.$this->map_name.'); 504 | 505 | '; 506 | 507 | if ($polyline['onclick'] != "") { 508 | $polyline_output .= ' 509 | google.maps.event.addListener(polyline_'.count($this->polylines).', "click", function() { 510 | '.$polyline['onclick'].' 511 | }); 512 | '; 513 | } 514 | if ($polyline['ondblclick'] != "") { 515 | $polyline_output .= ' 516 | google.maps.event.addListener(polyline_'.count($this->polylines).', "dblclick", function() { 517 | '.$polyline['ondblclick'].' 518 | }); 519 | '; 520 | } 521 | if ($polyline['onmousedown'] != "") { 522 | $polyline_output .= ' 523 | google.maps.event.addListener(polyline_'.count($this->polylines).', "mousedown", function() { 524 | '.$polyline['onmousedown'].' 525 | }); 526 | '; 527 | } 528 | if ($polyline['onmousemove'] != "") { 529 | $polyline_output .= ' 530 | google.maps.event.addListener(polyline_'.count($this->polylines).', "mousemove", function() { 531 | '.$polyline['onmousemove'].' 532 | }); 533 | '; 534 | } 535 | if ($polyline['onmouseout'] != "") { 536 | $polyline_output .= ' 537 | google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseout", function() { 538 | '.$polyline['onmouseout'].' 539 | }); 540 | '; 541 | } 542 | if ($polyline['onmouseover'] != "") { 543 | $polyline_output .= ' 544 | google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseover", function() { 545 | '.$polyline['onmouseover'].' 546 | }); 547 | '; 548 | } 549 | if ($polyline['onmouseup'] != "") { 550 | $polyline_output .= ' 551 | google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseup", function() { 552 | '.$polyline['onmouseup'].' 553 | }); 554 | '; 555 | } 556 | if ($polyline['onrightclick'] != "") { 557 | $polyline_output .= ' 558 | google.maps.event.addListener(polyline_'.count($this->polylines).', "rightclick", function() { 559 | '.$polyline['onrightclick'].' 560 | }); 561 | '; 562 | } 563 | 564 | array_push($this->polylines, $polyline_output); 565 | } 566 | } 567 | 568 | public function add_polygon($params = array()) 569 | { 570 | $polygon = array(); 571 | 572 | $polygon['points'] = array(); // The positions (latitude/longitude coordinates OR addresses) at which the polygon points will appear. NOTE: The first and last elements of the array must be the same 573 | $polygon['clickable'] = true; // Defines if the polygon is clickable 574 | $polygon['strokeColor'] = '#FF0000'; // The hex value of the polygons border color 575 | $polygon['strokeOpacity'] = '0.8'; // The opacity of the polygon border. 0 to 1.0 576 | $polygon['strokeWeight'] = '2'; // The thickness of the polygon border 577 | $polygon['fillColor'] = '#FF0000'; // The hex value of the polygons fill color 578 | $polygon['fillOpacity'] = '0.3'; // The opacity of the polygons fill 579 | $polygon['onclick'] = ''; // JavaScript performed when a polygon is clicked 580 | $polygon['ondblclick'] = ''; // JavaScript performed when a polygon is double-clicked 581 | $polygon['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a polygon 582 | $polygon['onmousemove'] = ''; // JavaScript performed when the mouse moves in the area of the polygon 583 | $polygon['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the polygon 584 | $polygon['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the polygon 585 | $polygon['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a polygon 586 | $polygon['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a polygon 587 | $polygon['zIndex'] = ''; // The zIndex of the polygon. If two polygons overlap, the polygon with the higher zIndex will appear on top 588 | 589 | $polygon_output = ''; 590 | 591 | foreach ($params as $key => $value) { 592 | if (isset($polygon[$key])) { 593 | $polygon[$key] = $value; 594 | } 595 | } 596 | 597 | if (count($polygon['points'])) { 598 | $polygon_output .= ' 599 | var polygon_plan_'.count($this->polygons).' = ['; 600 | $i = 0; 601 | $lat_long_output = ''; 602 | foreach ($polygon['points'] as $point) { 603 | if ($i > 0) { 604 | $polygon_output .= ','; 605 | } 606 | $lat_long_to_push = ''; 607 | if ($this->is_lat_long($point)) { 608 | $lat_long_to_push = $point; 609 | $polygon_output .= ' 610 | new google.maps.LatLng('.$point.') 611 | '; 612 | } else { 613 | $lat_long = $this->get_lat_long_from_address($point); 614 | $polygon_output .= ' 615 | new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')'; 616 | $lat_long_to_push = $lat_long[0].', '.$lat_long[1]; 617 | } 618 | $lat_long_output .= ' 619 | lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.')); 620 | '; 621 | $i++; 622 | } 623 | $polygon_output .= '];'; 624 | 625 | $polygon_output .= $lat_long_output; 626 | } 627 | 628 | $polygon_output .= ' 629 | var polygon_'.count($this->polygons).' = new google.maps.Polygon({ 630 | '; 631 | if (count($polygon['points'])) { 632 | $polygon_output .= 'path: polygon_plan_'.count($this->polygons).', 633 | '; 634 | } 635 | $polygon_output .= ' 636 | strokeColor: "'.$polygon['strokeColor'].'", 637 | strokeOpacity: '.$polygon['strokeOpacity'].', 638 | strokeWeight: '.$polygon['strokeWeight'].', 639 | fillColor: "'.$polygon['fillColor'].'", 640 | fillOpacity: '.$polygon['fillOpacity']; 641 | if (!$polygon['clickable']) { 642 | $polygon_output .= ', 643 | clickable: false'; 644 | } 645 | if ($polygon['zIndex'] != "" && is_numeric($polygon['zIndex'])) { 646 | $polygon_output .= ', 647 | zIndex: '.$polygon['zIndex']; 648 | } 649 | $polygon_output .= ' 650 | }); 651 | 652 | polygon_'.count($this->polygons).'.setMap('.$this->map_name.'); 653 | 654 | '; 655 | 656 | if ($polygon['onclick'] != "") { 657 | $polygon_output .= ' 658 | google.maps.event.addListener(polygon_'.count($this->polygons).', "click", function() { 659 | '.$polygon['onclick'].' 660 | }); 661 | '; 662 | } 663 | if ($polygon['ondblclick'] != "") { 664 | $polygon_output .= ' 665 | google.maps.event.addListener(polygon_'.count($this->polygons).', "dblclick", function() { 666 | '.$polygon['ondblclick'].' 667 | }); 668 | '; 669 | } 670 | if ($polygon['onmousedown'] != "") { 671 | $polygon_output .= ' 672 | google.maps.event.addListener(polygon_'.count($this->polygons).', "mousedown", function() { 673 | '.$polygon['onmousedown'].' 674 | }); 675 | '; 676 | } 677 | if ($polygon['onmousemove'] != "") { 678 | $polygon_output .= ' 679 | google.maps.event.addListener(polygon_'.count($this->polygons).', "mousemove", function() { 680 | '.$polygon['onmousemove'].' 681 | }); 682 | '; 683 | } 684 | if ($polygon['onmouseout'] != "") { 685 | $polygon_output .= ' 686 | google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseout", function() { 687 | '.$polygon['onmouseout'].' 688 | }); 689 | '; 690 | } 691 | if ($polygon['onmouseover'] != "") { 692 | $polygon_output .= ' 693 | google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseover", function() { 694 | '.$polygon['onmouseover'].' 695 | }); 696 | '; 697 | } 698 | if ($polygon['onmouseup'] != "") { 699 | $polygon_output .= ' 700 | google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseup", function() { 701 | '.$polygon['onmouseup'].' 702 | }); 703 | '; 704 | } 705 | if ($polygon['onrightclick'] != "") { 706 | $polygon_output .= ' 707 | google.maps.event.addListener(polygon_'.count($this->polygons).', "rightclick", function() { 708 | '.$polygon['onrightclick'].' 709 | }); 710 | '; 711 | } 712 | 713 | array_push($this->polygons, $polygon_output); 714 | } 715 | 716 | public function add_circle($params = array()) 717 | { 718 | $circle = array(); 719 | 720 | $circle['center'] = ''; // The center position (latitude/longitude coordinate OR addresse) at which the circle will appear 721 | $circle['clickable'] = true; // Defines if the circle is clickable 722 | $circle['radius'] = 0; // The circle radius (in metres) 723 | $circle['strokeColor'] = '0.8'; // The hex value of the circles border color 724 | $circle['strokeOpacity'] = '0.8'; // The opacity of the circle border 725 | $circle['strokeWeight'] = '2'; // The thickness of the circle border 726 | $circle['fillColor'] = '#FF0000'; // The hex value of the circles fill color 727 | $circle['fillOpacity'] = '0.3'; // The opacity of the circles fill 728 | $circle['onclick'] = ''; // JavaScript performed when a circle is clicked 729 | $circle['ondblclick'] = ''; // JavaScript performed when a circle is double-clicked 730 | $circle['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a circle 731 | $circle['onmousemove'] = ''; // JavaScript performed when the mouse moves in the area of the circle 732 | $circle['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the circle 733 | $circle['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the circle 734 | $circle['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a circle 735 | $circle['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a circle 736 | $circle['zIndex'] = ''; // The zIndex of the circle. If two circles overlap, the circle with the higher zIndex will appear on top 737 | 738 | $circle_output = ''; 739 | 740 | foreach ($params as $key => $value) { 741 | if (isset($circle[$key])) { 742 | $circle[$key] = $value; 743 | } 744 | } 745 | 746 | if ($circle['radius'] > 0 && $circle['center'] != "") { 747 | $lat_long_to_push = ''; 748 | if ($this->is_lat_long($circle['center'])) { 749 | $lat_long_to_push = $circle['center']; 750 | $circle_output = ' 751 | var circleCenter = new google.maps.LatLng('.$circle['center'].') 752 | '; 753 | } else { 754 | $lat_long = $this->get_lat_long_from_address($circle['center']); 755 | $circle_output = ' 756 | var circleCenter = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')'; 757 | $lat_long_to_push = $lat_long[0].', '.$lat_long[1]; 758 | } 759 | $circle_output .= ' 760 | lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.')); 761 | '; 762 | 763 | $circle_output .= ' 764 | var circleOptions = { 765 | strokeColor: "'.$circle['strokeColor'].'", 766 | strokeOpacity: '.$circle['strokeOpacity'].', 767 | strokeWeight: '.$circle['strokeWeight'].', 768 | fillColor: "'.$circle['fillColor'].'", 769 | fillOpacity: '.$circle['fillOpacity'].', 770 | map: '.$this->map_name.', 771 | center: circleCenter, 772 | radius: '.$circle['radius']; 773 | if (!$circle['clickable']) { 774 | $circle_output .= ', 775 | clickable: false'; 776 | } 777 | if ($circle['zIndex'] != "" && is_numeric($circle['zIndex'])) { 778 | $circle_output .= ', 779 | zIndex: '.$circle['zIndex']; 780 | } 781 | $circle_output .= ' 782 | }; 783 | var circle_'.count($this->circles).' = new google.maps.Circle(circleOptions); 784 | '; 785 | 786 | if ($circle['onclick'] != "") { 787 | $circle_output .= ' 788 | google.maps.event.addListener(circle_'.count($this->circles).', "click", function() { 789 | '.$circle['onclick'].' 790 | }); 791 | '; 792 | } 793 | if ($circle['ondblclick'] != "") { 794 | $circle_output .= ' 795 | google.maps.event.addListener(circle_'.count($this->circles).', "dblclick", function() { 796 | '.$circle['ondblclick'].' 797 | }); 798 | '; 799 | } 800 | if ($circle['onmousedown'] != "") { 801 | $circle_output .= ' 802 | google.maps.event.addListener(circle_'.count($this->circles).', "mousedown", function() { 803 | '.$circle['onmousedown'].' 804 | }); 805 | '; 806 | } 807 | if ($circle['onmousemove'] != "") { 808 | $circle_output .= ' 809 | google.maps.event.addListener(circle_'.count($this->circles).', "mousemove", function() { 810 | '.$circle['onmousemove'].' 811 | }); 812 | '; 813 | } 814 | if ($circle['onmouseout'] != "") { 815 | $circle_output .= ' 816 | google.maps.event.addListener(circle_'.count($this->circles).', "mouseout", function() { 817 | '.$circle['onmouseout'].' 818 | }); 819 | '; 820 | } 821 | if ($circle['onmouseover'] != "") { 822 | $circle_output .= ' 823 | google.maps.event.addListener(circle_'.count($this->circles).', "mouseover", function() { 824 | '.$circle['onmouseover'].' 825 | }); 826 | '; 827 | } 828 | if ($circle['onmouseup'] != "") { 829 | $circle_output .= ' 830 | google.maps.event.addListener(circle_'.count($this->circles).', "mouseup", function() { 831 | '.$circle['onmouseup'].' 832 | }); 833 | '; 834 | } 835 | if ($circle['onrightclick'] != "") { 836 | $circle_output .= ' 837 | google.maps.event.addListener(circle_'.count($this->circles).', "rightclick", function() { 838 | '.$circle['onrightclick'].' 839 | }); 840 | '; 841 | } 842 | 843 | array_push($this->circles, $circle_output); 844 | } 845 | } 846 | 847 | public function add_rectangle($params = array()) 848 | { 849 | $rectangle = array(); 850 | 851 | $rectangle['positionSW'] = ''; // The South-West position (latitude/longitude coordinate OR address) at which the rectangle will appear 852 | $rectangle['positionNE'] = ''; // The North-East position(latitude/longitude coordinate OR address) at which the rectangle will appear 853 | $rectangle['clickable'] = true; // Defines if the rectangle is clickable 854 | $rectangle['strokeColor'] = '0.8'; // The hex value of the rectangles border color 855 | $rectangle['strokeOpacity'] = '0.8'; // The opacity of the rectangle border 856 | $rectangle['strokeWeight'] = '2'; // The thickness of the rectangle border 857 | $rectangle['fillColor'] = '#FF0000'; // The hex value of the rectangles fill color 858 | $rectangle['fillOpacity'] = '0.3'; // The opacity of the rectangles fill 859 | $rectangle['onclick'] = ''; // JavaScript performed when a rectangle is clicked 860 | $rectangle['ondblclick'] = ''; // JavaScript performed when a rectangle is double-clicked 861 | $rectangle['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a rectangle 862 | $rectangle['onmousemove'] = ''; // JavaScript performed when the mouse moves in the area of the rectangle 863 | $rectangle['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the rectangle 864 | $rectangle['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the rectangle 865 | $rectangle['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a rectangle 866 | $rectangle['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a rectangle 867 | $rectangle['zIndex'] = ''; // The zIndex of the rectangle. If two rectangles overlap, the rectangle with the higher zIndex will appear on top 868 | 869 | $rectangle_output = ''; 870 | 871 | foreach ($params as $key => $value) { 872 | if (isset($rectangle[$key])) { 873 | $rectangle[$key] = $value; 874 | } 875 | } 876 | 877 | if ($rectangle['positionSW'] != "" && $rectangle['positionNE'] != "") { 878 | $lat_long_to_push = ''; 879 | if ($this->is_lat_long($rectangle['positionSW'])) { 880 | $lat_long_to_push = $rectangle['positionSW']; 881 | $rectangle_output .= ' 882 | var positionSW = new google.maps.LatLng('.$rectangle['positionSW'].') 883 | '; 884 | } else { 885 | $lat_long = $this->get_lat_long_from_address($rectangle['positionSW']); 886 | $rectangle_output .= ' 887 | var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')'; 888 | $lat_long_to_push = $lat_long[0].', '.$lat_long[1]; 889 | } 890 | $rectangle_output .= ' 891 | lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.')); 892 | '; 893 | 894 | $lat_long_to_push = ''; 895 | if ($this->is_lat_long($rectangle['positionNE'])) { 896 | $lat_long_to_push = $rectangle['positionNE']; 897 | $rectangle_output .= ' 898 | var positionNE = new google.maps.LatLng('.$rectangle['positionNE'].') 899 | '; 900 | } else { 901 | $lat_long = $this->get_lat_long_from_address($rectangle['positionNE']); 902 | $rectangle_output .= ' 903 | var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')'; 904 | $lat_long_to_push = $lat_long[0].', '.$lat_long[1]; 905 | } 906 | $rectangle_output .= ' 907 | lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.')); 908 | '; 909 | 910 | $rectangle_output .= ' 911 | var rectangleOptions = { 912 | strokeColor: "'.$rectangle['strokeColor'].'", 913 | strokeOpacity: '.$rectangle['strokeOpacity'].', 914 | strokeWeight: '.$rectangle['strokeWeight'].', 915 | fillColor: "'.$rectangle['fillColor'].'", 916 | fillOpacity: '.$rectangle['fillOpacity'].', 917 | map: '.$this->map_name.', 918 | bounds: new google.maps.LatLngBounds(positionSW, positionNE)'; 919 | if (!$rectangle['clickable']) { 920 | $rectangle_output .= ', 921 | clickable: false'; 922 | } 923 | if ($rectangle['zIndex'] != "" && is_numeric($rectangle['zIndex'])) { 924 | $rectangle_output .= ', 925 | zIndex: '.$rectangle['zIndex']; 926 | } 927 | $rectangle_output .= ' 928 | };'; 929 | 930 | $rectangle_output .= ' 931 | var rectangle_'.count($this->rectangles).' = new google.maps.Rectangle(rectangleOptions); 932 | '; 933 | 934 | if ($rectangle['onclick'] != "") { 935 | $rectangle_output .= ' 936 | google.maps.event.addListener(rectangle_'.count($this->rectangles).', "click", function() { 937 | '.$rectangle['onclick'].' 938 | }); 939 | '; 940 | } 941 | if ($rectangle['ondblclick'] != "") { 942 | $rectangle_output .= ' 943 | google.maps.event.addListener(rectangle_'.count($this->rectangles).', "dblclick", function() { 944 | '.$rectangle['ondblclick'].' 945 | }); 946 | '; 947 | } 948 | if ($rectangle['onmousedown'] != "") { 949 | $rectangle_output .= ' 950 | google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousedown", function() { 951 | '.$rectangle['onmousedown'].' 952 | }); 953 | '; 954 | } 955 | if ($rectangle['onmousemove'] != "") { 956 | $rectangle_output .= ' 957 | google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousemove", function() { 958 | '.$rectangle['onmousemove'].' 959 | }); 960 | '; 961 | } 962 | if ($rectangle['onmouseout'] != "") { 963 | $rectangle_output .= ' 964 | google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseout", function() { 965 | '.$rectangle['onmouseout'].' 966 | }); 967 | '; 968 | } 969 | if ($rectangle['onmouseover'] != "") { 970 | $rectangle_output .= ' 971 | google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseover", function() { 972 | '.$rectangle['onmouseover'].' 973 | }); 974 | '; 975 | } 976 | if ($rectangle['onmouseup'] != "") { 977 | $rectangle_output .= ' 978 | google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseup", function() { 979 | '.$rectangle['onmouseup'].' 980 | }); 981 | '; 982 | } 983 | if ($rectangle['onrightclick'] != "") { 984 | $rectangle_output .= ' 985 | google.maps.event.addListener(rectangle_'.count($this->rectangles).', "rightclick", function() { 986 | '.$rectangle['onrightclick'].' 987 | }); 988 | '; 989 | } 990 | 991 | array_push($this->rectangles, $rectangle_output); 992 | } 993 | } 994 | 995 | public function add_ground_overlay($params = array()) 996 | { 997 | $overlay = array(); 998 | 999 | $overlay['image'] = ''; // JavaScript performed when a ground overlay is clicked 1000 | $overlay['positionSW'] = ''; // The South-West position (latitude/longitude coordinate OR addresse) at which the ground overlay will appear 1001 | $overlay['positionNE'] = ''; // The North-East position (latitude/longitude coordinate OR addresse) at which the ground overlay will appear 1002 | $overlay['clickable'] = true; // Defines if the ground overlay is clickable 1003 | $overlay['onclick'] = ''; // JavaScript performed when a ground overlay is clicked 1004 | 1005 | $overlay_output = ''; 1006 | 1007 | foreach ($params as $key => $value) { 1008 | if (isset($overlay[$key])) { 1009 | $overlay[$key] = $value; 1010 | } 1011 | } 1012 | 1013 | if ($overlay['image'] != "" && $overlay['positionSW'] != "" && $overlay['positionNE'] != "") { 1014 | $lat_long_to_push = ''; 1015 | if ($this->is_lat_long($overlay['positionSW'])) { 1016 | $lat_long_to_push = $overlay['positionSW']; 1017 | $overlay_output .= ' 1018 | var positionSW = new google.maps.LatLng('.$overlay['positionSW'].') 1019 | '; 1020 | } else { 1021 | $lat_long = $this->get_lat_long_from_address($overlay['positionSW']); 1022 | $overlay_output .= ' 1023 | var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')'; 1024 | $lat_long_to_push = $lat_long[0].', '.$lat_long[1]; 1025 | } 1026 | $overlay_output .= ' 1027 | lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.')); 1028 | '; 1029 | 1030 | $lat_long_to_push = ''; 1031 | if ($this->is_lat_long($overlay['positionNE'])) { 1032 | $lat_long_to_push = $overlay['positionNE']; 1033 | $overlay_output .= ' 1034 | var positionNE = new google.maps.LatLng('.$overlay['positionNE'].') 1035 | '; 1036 | } else { 1037 | $lat_long = $this->get_lat_long_from_address($overlay['positionNE']); 1038 | $overlay_output .= ' 1039 | var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')'; 1040 | $lat_long_to_push = $lat_long[0].', '.$lat_long[1]; 1041 | } 1042 | $overlay_output .= ' 1043 | lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.')); 1044 | '; 1045 | 1046 | $overlay_output .= ' 1047 | var overlay_'.count($this->overlays).' = new google.maps.GroundOverlay("'.$overlay['image'].'", new google.maps.LatLngBounds(positionSW, positionNE), { map: '.$this->map_name; 1048 | if (!$overlay['clickable']) { 1049 | $overlay_output .= ', clickable: false'; 1050 | } 1051 | $overlay_output .= '}); 1052 | '; 1053 | 1054 | if ($overlay['onclick'] != "") { 1055 | $overlay_output .= ' 1056 | google.maps.event.addListener(overlay_'.count($this->overlays).', "click", function() { 1057 | '.$overlay['onclick'].' 1058 | }); 1059 | '; 1060 | } 1061 | 1062 | array_push($this->overlays, $overlay_output); 1063 | } 1064 | } 1065 | 1066 | public function create_map() 1067 | { 1068 | $this->output_js = ''; 1069 | $this->output_js_contents = ''; 1070 | $this->output_html = ''; 1071 | 1072 | if ($this->maps_loaded == 0) { 1073 | if ($this->apiKey != "") { 1074 | $apiLocation = 'https://maps.googleapis.com/maps/api/js?key='.$this->apiKey.'&'; 1075 | } else { 1076 | $apiLocation = 'https://maps.google.com/maps/api/js?'; 1077 | } 1078 | if ($this->region != "" && strlen($this->region) == 2) { 1079 | $apiLocation .= '®ion='.strtoupper($this->region); 1080 | } 1081 | if ($this->language != "") { 1082 | $apiLocation .= '&language='.$this->language; 1083 | } 1084 | $libraries = array(); 1085 | if ($this->adsense != "") { 1086 | array_push($libraries, 'adsense'); 1087 | } 1088 | if ($this->places != "") { 1089 | array_push($libraries, 'places'); 1090 | } 1091 | if ($this->panoramio) { 1092 | array_push($libraries, 'panoramio'); 1093 | } 1094 | if ($this->drawing) { 1095 | array_push($libraries, 'drawing'); 1096 | } 1097 | if (count($libraries)) { 1098 | $apiLocation .= '&libraries='.implode(",", $libraries); 1099 | } 1100 | 1101 | if (!$this->loadAsynchronously) { 1102 | $this->output_js .= ' 1103 | '; 1104 | } 1105 | 1106 | if ($this->cluster) { 1107 | $this->output_js .= ' 1108 | 1109 | 1110 | '; 1111 | } 1112 | } 1113 | if ($this->jsfile == "") { 1114 | $this->output_js .= ' 1115 | '; 2147 | } 2148 | } 2149 | } 2150 | 2151 | if ($this->jsfile == "") { 2152 | $this->output_js .= ' 2153 | //]]> 2154 | '; 2155 | } 2156 | 2157 | // set height and width 2158 | if (is_numeric($this->map_width)) { // if no width type set 2159 | $this->map_width = $this->map_width.'px'; 2160 | } 2161 | if (is_numeric($this->map_height)) { // if no height type set 2162 | $this->map_height = $this->map_height.'px'; 2163 | } 2164 | // 2165 | 2166 | $this->output_html .= '
class != "") ? ' class="'.$this->class.'"' : '').'>
'; 2167 | 2168 | ++$this->maps_loaded; 2169 | 2170 | return array('js' => $this->output_js, 'html' => $this->output_html, 'markers' => $this->markersInfo); 2171 | } 2172 | 2173 | public function is_lat_long($input) 2174 | { 2175 | $input = str_replace(", ", ",", trim($input)); 2176 | $input = explode(",", $input); 2177 | if (count($input) == 2) { 2178 | if (is_numeric($input[0]) && is_numeric($input[1])) { // is a lat long 2179 | return true; 2180 | } else { // not a lat long - incorrect values 2181 | return false; 2182 | } 2183 | } else { // not a lat long - too many parts 2184 | return false; 2185 | } 2186 | } 2187 | 2188 | public function get_lat_long_from_address($address, $attempts = 0) 2189 | { 2190 | $lat = 0; 2191 | $lng = 0; 2192 | 2193 | $error = ''; 2194 | 2195 | if ($this->geocodeCaching) { // if caching of geocode requests is activated 2196 | 2197 | $CI = & get_instance(); 2198 | $CI->load->database(); 2199 | $CI->db->select("latitude,longitude"); 2200 | $CI->db->from("geocoding"); 2201 | $CI->db->where("address", trim(strtolower($address))); 2202 | $query = $CI->db->get(); 2203 | 2204 | if ($query->num_rows() > 0) { 2205 | $row = $query->row(); 2206 | 2207 | return array($row->latitude, $row->longitude); 2208 | } 2209 | } 2210 | //utf8_encode($address) will return only english adress mean it's take only english address. 2211 | // Remove utf8_encode from urlencode then it'll support all languages(eg. en, ur, chinese, russian, japanese, greek etc.) 2212 | // $data_location = "https://maps.google.com/maps/api/geocode/json?address=".urlencode(utf8_encode($address)); //Old One just for english 2213 | $data_location = "https://maps.google.com/maps/api/geocode/json?address=".urlencode($address); // New One for every language. 2214 | if ($this->region != "" && strlen($this->region) == 2) { 2215 | $data_location .= "®ion=".$this->region; 2216 | } 2217 | $data = file_get_contents($data_location); 2218 | 2219 | $data = json_decode($data); 2220 | 2221 | if ($data->status == "OK") { 2222 | $lat = $data->results[0]->geometry->location->lat; 2223 | $lng = $data->results[0]->geometry->location->lng; 2224 | 2225 | if ($this->geocodeCaching) { // if we to need to cache this result 2226 | if ($address != "" && $lat != 0 && $lng != 0) { 2227 | $data = array( 2228 | "address" => trim(strtolower($address)), 2229 | "latitude" => $lat, 2230 | "longitude" => $lng, 2231 | ); 2232 | $CI->db->insert("geocoding", $data); 2233 | } 2234 | } 2235 | } else { 2236 | if ($data->status == "OVER_QUERY_LIMIT") { 2237 | $error = $data->status; 2238 | if ($attempts < 2) { 2239 | sleep(1); 2240 | ++$attempts; 2241 | list($lat, $lng, $error) = $this->get_lat_long_from_address($address, $attempts); 2242 | } 2243 | } 2244 | } 2245 | 2246 | return array($lat, $lng, $error); 2247 | } 2248 | } 2249 | -------------------------------------------------------------------------------- /src/GeneaLabs/Phpgmaps/PhpgmapsServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton('phpgmaps', function () { 34 | $phpgmaps = new Phpgmaps(); 35 | $phpgmaps->apiKey = config('services.google.maps.api-key'); 36 | 37 | return $phpgmaps; 38 | }); 39 | 40 | 41 | AliasLoader::getInstance()->alias('Gmaps', PhpgmapsFacade::class); 42 | } 43 | 44 | /** 45 | * Get the services provided by the provider. 46 | * 47 | * @return array 48 | */ 49 | public function provides() 50 | { 51 | return array('phpgmaps'); 52 | } 53 | } 54 | --------------------------------------------------------------------------------