Passed
Push — master ( 7817e0...aac951 )
by Mike
02:00
created

Map::add_rectangle()   F

Complexity

Conditions 18
Paths 12291

Size

Total Lines 145
Code Lines 95

Duplication

Lines 78
Ratio 53.79 %

Importance

Changes 0
Metric Value
dl 78
loc 145
rs 2
c 0
b 0
f 0
cc 18
eloc 95
nc 12291
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace GeneaLabs\LaravelMaps;
2
3
class Map
4
{
5
6
    protected $output_js;
7
    protected $output_js_contents;
8
    protected $output_html;
9
10
    public $adsense = false;                    // Whether Google Adsense For Content should be enabled
11
    public $adsenseChannelNumber = '';                        // The Adsense channel number for tracking the performance of this AdUnit
12
    public $adsenseFormat = 'HALF_BANNER';            // The format of the AdUnit
13
    public $adsensePosition = 'TOP_CENTER';                // The position of the AdUnit
14
    public $adsensePublisherID = '';                        // Your Google AdSense publisher ID
15
    public $apiKey = '';                        // If you've got an API key you can use it by passing this parameter. Setup an API key here: https://code.google.com/apis/console
16
    public $backgroundColor = '';                        // A hex color value shown as the map background when tiles have not yet loaded as the user pans
17
    public $bicyclingOverlay = false;                    // If set to TRUE will overlay bicycling information (ie. bike paths and suggested routes) onto the map by default
18
    public $center = '37.4419, -122.1419';        // Sets the default center location (lat/long co-ordinate or address) of the map. If defaulting to the users location set to "auto"
19
20
    public $class = '';                        // A class name if wishing to style the map further through CSS. Can also be useful if wanting it to be responsive etc.
21
    public $cluster = false;                    // Whether to cluster markers
22
    public $clusterGridSize = 60;                        // The grid size of a cluster in pixels
23
    public $clusterMaxZoom = '';                        // The maximum zoom level that a marker can be part of a cluster
24
    public $clusterZoomOnClick = true;                        // Whether the default behaviour of clicking on a cluster is to zoom into it
25
    public $clusterAverageCenter = false;                    // Whether the center of each cluster should be the average of all markers in the cluster
26
    public $clusterMinimumClusterSize = 2;                        // The minimum number of markers to be in a cluster before the markers are hidden and a count is shown
27
    public $clusterStyles = []; 				// (object) An array that has style properties: *  'url': (string) The image url. *  'height': (number) The image height. *  'width': (number) The image width. *  'anchor': (Array) The anchor position of the label text. *  'textColor': (string) The text color. *  'textSize': (number) The text size. *  'backgroundPosition': (string) The position of the backgound x, y.
28
    public $disableDefaultUI = false;                    // If set to TRUE will hide the default controls (ie. zoom, scale etc)
29
    public $disableDoubleClickZoom = false;                    // If set to TRUE will disable zooming when a double click occurs
30
    public $disableMapTypeControl = false;                    // If set to TRUE will hide the MapType control (ie. Map, Satellite, Hybrid, Terrain)
31
    public $disableNavigationControl = false;                    // If set to TRUE will hide the Navigation control (ie. zoom in/out, pan)
32
    public $disableScaleControl = false;                    // If set to TRUE will hide the Scale control
33
    public $disableStreetViewControl = false;                    // If set to TRUE will hide the Street View control
34
    public $draggable = true;                        // If set to FALSE will prevent the map from being dragged around
35
    public $draggableCursor = '';                        // The name or url of the cursor to display on a draggable object
36
    public $draggingCursor = '';                        // The name or url of the cursor to display when an object is being dragged
37
    public $geocodeCaching = false;                    // If set to TRUE will cache any geocode requests made when an address is used instead of a lat/long. Requires DB table to be created (see documentation)
38
    public $https = false;                    // If set to TRUE will load the Google Maps JavaScript API over HTTPS, allowing you to utilize the API within your HTTPS secure application
39
    public $navigationControlPosition = '';                        // The position of the Navigation control, eg. 'BOTTOM_RIGHT'
40
    public $infowindowMaxWidth = 0;                        // The maximum width of the infowindow in pixels. Expecting an integer without units
41
    public $keyboardShortcuts = true;                        // If set to FALSE will disable to map being controlled via the keyboard
42
    public $jsfile = '';                        // Set this to the path of an external JS file if you wish the JavaScript to be placed in a file rather than output directly into the <head></head> 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 <div></div> 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 create($center)
160
    {
161
        $gmapsConfig = [];
162
        $gmapsConfig['center'] = $center->latitude . ', ' . $center->longitude;
163
        $gmapsConfig['onboundschanged'] = "if ((typeof centreGot === 'undefined') || !centreGot) {
164
            var mapCentre = map.getCenter();
165
            marker_0.setOptions({
166
                position: new google.maps.LatLng(mapCentre.lat(), mapCentre.lng())
167
            });
168
        }
169
        centreGot = true;";
170
        $this->initialize($gmapsConfig);
171
        $gmapsMarker = [];
172
        $gmapsMarker['position'] = $center->latitude . ', ' . $center->longitude;
173
        $gmapsMarker['animation'] = 'DROP';
174
        $gmapsMarker['highlightBackgroundColor'] = 'ff0000';
175
        $this->add_marker($gmapsMarker);
176
177
        return $this->create_map();
178
    }
179
180
    public function initialize($config = array())
181
    {
182
        foreach ($config as $key => $val) {
183
            if (isset($this->$key)) {
184
                $this->$key = $val;
185
            }
186
        }
187
    }
188
189
    public function add_marker($params = array())
190
    {
191
        $marker = array();
192
        $this->markersInfo['marker_'.count($this->markers)] = array();
193
194
        $marker['position'] = '';                                // The position (lat/long co-ordinate or address) at which the marker will appear
195
        $marker['infowindow_content'] = '';                        // If not blank, creates an infowindow (aka bubble) with the content provided. Can be plain text or HTML
196
        $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
197
        $marker['clickable'] = true;                            // Defines if the marker is clickable
198
        $marker['cursor'] = '';                                    // The name or url of the cursor to display on hover
199
        $marker['draggable'] = false;                            // Defines if the marker is draggable
200
        $marker['flat'] = false;                                // If set to TRUE will not display a shadow beneath the icon
201
        $marker['icon'] = '';                                    // The name or url of the icon to use for the marker
202
        $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
203
        $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')
204
        $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')
205
        $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
206
        $marker['animation'] = '';                                // blank, 'DROP' or 'BOUNCE'
207
        $marker['onclick'] = '';                                // JavaScript performed when a marker is clicked
208
        $marker['ondblclick'] = '';                                // JavaScript performed when a marker is double-clicked
209
        $marker['ondrag'] = '';                                    // JavaScript repeatedly performed while the marker is being dragged
210
        $marker['ondragstart'] = '';                            // JavaScript performed when a marker is started to be dragged
211
        $marker['ondragend'] = '';                                // JavaScript performed when a draggable marker is dropped
212
        $marker['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a marker
213
        $marker['onmouseout'] = '';                                // JavaScript performed when the mouse leaves the area of the marker icon
214
        $marker['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the marker icon
215
        $marker['onmouseup'] = '';                                // JavaScript performed when a mouseup event occurs on a marker
216
        $marker['onpositionchanged'] = '';                        // JavaScript performed when the markers position changes
217
        $marker['onrightclick'] = '';                            // JavaScript performed when a right-click occurs on a marker
218
        $marker['raiseondrag'] = true;                            // If FALSE, disables the raising and lowering of the icon when a marker is being dragged
219
        $marker['shadow'] = '';                                    // The name or url of the icon's shadow
220
        $marker['title'] = '';                                    // The tooltip text to show on hover
221
        $marker['visible'] = true;                                // Defines if the marker is visible by default
222
        $marker['zIndex'] = '';                                    // The zIndex of the marker. If two markers overlap, the marker with the higher zIndex will appear on top
223
        $marker['label'] = '';                                    // The label of the marker.
224
225
        $marker_output = '';
226
227
        foreach ($params as $key => $value) {
228
            if (isset($marker[$key])) {
229
                $marker[$key] = $value;
230
            }
231
        }
232
233
        $marker_id = count($this->markers);
234
        if (trim($marker['id']) != "") {
235
            $marker_id = $marker['id'];
236
        }
237
238
        if ($marker['position'] != "") {
239
            if ($this->is_lat_long($marker['position'])) {
240
                $marker_output .= '
241
			var myLatlng = new google.maps.LatLng('.$marker['position'].');
242
			';
243
                $explodePosition = explode(",", $marker['position']);
244
                $this->markersInfo['marker_'.$marker_id]['latitude'] = trim($explodePosition[0]);
245
                $this->markersInfo['marker_'.$marker_id]['longitude'] = trim($explodePosition[1]);
246
            } else {
247
                $lat_long = $this->get_lat_long_from_address($marker['position']);
248
                $marker_output .= '
249
			var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');';
250
                $this->markersInfo['marker_'.$marker_id]['latitude'] = $lat_long[0];
251
                $this->markersInfo['marker_'.$marker_id]['longitude'] = $lat_long[1];
252
            }
253
        }
254
255
        if ($marker['icon'] != "") {
256
            $marker_output .= '
257
				var marker_icon = {
258
					url: "'.$marker['icon'].'"';
259
            if ($marker['icon_size'] != "") {
260
                $marker_output .= ',
261
					size: new google.maps.Size('.$marker['icon_size'].')';
262
            }
263
            if ($marker['icon_scaledSize'] != "") {
264
                $marker_output .= ',
265
					scaledSize: new google.maps.Size('.$marker['icon_scaledSize'].')';
266
            }
267
            if ($marker['icon_origin'] != "") {
268
                $marker_output .= ',
269
					origin: new google.maps.Point('.$marker['icon_origin'].')';
270
            }
271
            if ($marker['icon_anchor'] != "") {
272
                $marker_output .= ',
273
					anchor: new google.maps.Point('.$marker['icon_anchor'].')';
274
            }
275
            $marker_output .= '};
276
			';
277
        }
278
279
        $marker_output .= '
280
			var markerOptions = {
281
				map: '.$this->map_name;
282
        if ($marker['position'] != "") {
283
            $marker_output .= ',
284
				position: myLatlng';
285
        }
286
        if (!$marker['clickable']) {
287
            $marker_output .= ',
288
				clickable: false';
289
        }
290
        if ($marker['cursor'] != "") {
291
            $marker_output .= ',
292
				cursor: "'.$marker['cursor'].'"';
293
        }
294
        if ($marker['draggable']) {
295
            $marker_output .= ',
296
				draggable: true';
297
        }
298
        if ($marker['flat']) {
299
            $marker_output .= ',
300
				flat: true';
301
        }
302
        if ($marker['icon'] != "") {
303
            $marker_output .= ',
304
				icon: marker_icon';
305
        }
306
        if (!$marker['raiseondrag']) {
307
            $marker_output .= ',
308
				raiseOnDrag: false';
309
        }
310
        if ($marker['shadow'] != "") {
311
            $marker_output .= ',
312
				shadow: "'.$marker['shadow'].'"';
313
        }
314
        if ($marker['title'] != "") {
315
            $marker_output .= ',
316
				title: "'.$marker['title'].'"';
317
            $this->markersInfo['marker_'.$marker_id]['title'] = $marker['title'];
318
        }
319
        if (!$marker['visible']) {
320
            $marker_output .= ',
321
				visible: false';
322
        }
323
        if ($marker['zIndex'] != "" && is_numeric($marker['zIndex'])) {
324
            $marker_output .= ',
325
				zIndex: '.$marker['zIndex'];
326
        }
327
        if ($marker['animation'] != "" && (strtoupper($marker['animation']) == "DROP" || strtoupper($marker['animation'] == "BOUNCE"))) {
328
            $marker_output .= ',
329
				animation:  google.maps.Animation.'.strtoupper($marker['animation']);
330
        }
331
        if ($marker['label'] != "") {
332
            $marker_output .= ',
333
				label: "'.$marker['label'].'"';
334
        }
335
336
337
338
        $marker_output .= '
339
			};
340
			marker_'.$marker_id.' = createMarker_'.$this->map_name.'(markerOptions);
341
			';
342
343
        if ($marker['infowindow_content'] != "") {
344
345
            // Escape any quotes in the event that HTML is being added to the infowindow
346
            $marker['infowindow_content'] = str_replace('\"', '"', $marker['infowindow_content']);
347
            $marker['infowindow_content'] = str_replace('"', '\"', $marker['infowindow_content']);
348
349
            $marker_output .= '
350
			marker_'.$marker_id.'.set("content", "'.$marker['infowindow_content'].'");
351
352
			google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
353
				iw_'.$this->map_name.'.setContent(this.get("content"));
354
				iw_'.$this->map_name.'.open('.$this->map_name.', this);
355
			';
356
            if ($marker['onclick'] != "") {
357
                $marker_output .= $marker['onclick'].'
358
			';
359
            }
360
            $marker_output .= '
361
			});
362
			';
363
        } else {
364
            if ($marker['onclick'] != "") {
365
                $marker_output .= '
366
				google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
367
					'.$marker['onclick'].'
368
				});
369
				';
370
            }
371
        }
372
373
        if ($marker['ondblclick'] != "") {
374
            $marker_output .= '
375
			google.maps.event.addListener(marker_'.$marker_id.', "dblclick", function(event) {
376
				'.$marker['ondblclick'].'
377
			});
378
			';
379
        }
380
        if ($marker['onmousedown'] != "") {
381
            $marker_output .= '
382
			google.maps.event.addListener(marker_'.$marker_id.', "mousedown", function(event) {
383
				'.$marker['onmousedown'].'
384
			});
385
			';
386
        }
387
        if ($marker['onmouseout'] != "") {
388
            $marker_output .= '
389
			google.maps.event.addListener(marker_'.$marker_id.', "mouseout", function(event) {
390
				'.$marker['onmouseout'].'
391
			});
392
			';
393
        }
394
        if ($marker['onmouseover'] != "") {
395
            $marker_output .= '
396
			google.maps.event.addListener(marker_'.$marker_id.', "mouseover", function(event) {
397
				'.$marker['onmouseover'].'
398
			});
399
			';
400
        }
401
        if ($marker['onmouseup'] != "") {
402
            $marker_output .= '
403
			google.maps.event.addListener(marker_'.$marker_id.', "mouseup", function(event) {
404
				'.$marker['onmouseup'].'
405
			});
406
			';
407
        }
408
        if ($marker['onpositionchanged'] != "") {
409
            $marker_output .= '
410
			google.maps.event.addListener(marker_'.$marker_id.', "position_changed", function(event) {
411
				'.$marker['onpositionchanged'].'
412
			});
413
			';
414
        }
415
        if ($marker['onrightclick'] != "") {
416
            $marker_output .= '
417
			google.maps.event.addListener(marker_'.$marker_id.', "rightclick", function(event) {
418
				'.$marker['onrightclick'].'
419
			});
420
			';
421
        }
422
423
        if ($marker['draggable']) {
424
            if ($marker['ondrag'] != "") {
425
                $marker_output .= '
426
				google.maps.event.addListener(marker_'.$marker_id.', "drag", function(event) {
427
					'.$marker['ondrag'].'
428
				});
429
				';
430
            }
431
            if ($marker['ondragend'] != "") {
432
                $marker_output .= '
433
				google.maps.event.addListener(marker_'.$marker_id.', "dragend", function(event) {
434
					'.$marker['ondragend'].'
435
				});
436
				';
437
            }
438
            if ($marker['ondragstart'] != "") {
439
                $marker_output .= '
440
				google.maps.event.addListener(marker_'.$marker_id.', "dragstart", function(event) {
441
					'.$marker['ondragstart'].'
442
				});
443
				';
444
            }
445
        }
446
447
        array_push($this->markers, $marker_output);
448
    }
449
450
    public function add_polyline($params = array())
451
    {
452
        $polyline = array();
453
454
        $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.
455
        $polyline['clickable'] = true;                            // Defines if the polyline is clickable
456
        $polyline['strokeColor'] = '#FF0000';                    // The hex value of the polylines color
457
        $polyline['strokeOpacity'] = '1.0';                        // The opacity of the polyline. 0 to 1.0
458
        $polyline['strokeWeight'] = '2';                        // The thickness of the polyline
459
        $polyline['onclick'] = '';                                // JavaScript performed when a polyline is clicked
460
        $polyline['ondblclick'] = '';                            // JavaScript performed when a polyline is double-clicked
461
        $polyline['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a polyline
462
        $polyline['onmousemove'] = '';                            // JavaScript performed when the mouse moves in the area of the polyline
463
        $polyline['onmouseout'] = '';                            // JavaScript performed when the mouse leaves the area of the polyline
464
        $polyline['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the polyline
465
        $polyline['onmouseup'] = '';                            // JavaScript performed when a mouseup event occurs on a polyline
466
        $polyline['onrightclick'] = '';                            // JavaScript performed when a right-click occurs on a polyline
467
        $polyline['zIndex'] = '';                                // The zIndex of the polyline. If two polylines overlap, the polyline with the higher zIndex will appear on top
468
469
        $polyline_output = '';
470
471
        foreach ($params as $key => $value) {
472
            if (isset($polyline[$key])) {
473
                $polyline[$key] = $value;
474
            }
475
        }
476
477
        if (count($polyline['points'])) {
478
            $polyline_output .= '
479
				var polyline_plan_'.count($this->polylines).' = [';
480
            $i = 0;
481
            $lat_long_output = '';
482 View Code Duplication
            foreach ($polyline['points'] as $point) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
483
                if ($i > 0) {
484
                    $polyline_output .= ',';
485
                }
486
                $lat_long_to_push = '';
487
                if ($this->is_lat_long($point)) {
488
                    $lat_long_to_push = $point;
489
                    $polyline_output .= '
490
					new google.maps.LatLng('.$point.')
491
					';
492
                } else {
493
                    $lat_long = $this->get_lat_long_from_address($point);
494
                    $polyline_output .= '
495
					new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
496
                    $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
497
                }
498
                $lat_long_output .= '
499
					lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
500
				';
501
                $i++;
502
            }
503
            $polyline_output .= '];';
504
505
            $polyline_output .= $lat_long_output;
506
507
            $polyline_output .= '
508
				var polyline_'.count($this->polylines).' = new google.maps.Polyline({
509
    				path: polyline_plan_'.count($this->polylines).',
510
    				strokeColor: "'.$polyline['strokeColor'].'",
511
    				strokeOpacity: '.$polyline['strokeOpacity'].',
512
    				strokeWeight: '.$polyline['strokeWeight'];
513
            if (!$polyline['clickable']) {
514
                $polyline_output .= ',
515
					clickable: false';
516
            }
517
            if ($polyline['zIndex'] != "" && is_numeric($polyline['zIndex'])) {
518
                $polyline_output .= ',
519
					zIndex: '.$polyline['zIndex'];
520
            }
521
            $polyline_output .= '
522
				});
523
524
				polyline_'.count($this->polylines).'.setMap('.$this->map_name.');
525
526
			';
527
528 View Code Duplication
            if ($polyline['onclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
529
                $polyline_output .= '
530
				google.maps.event.addListener(polyline_'.count($this->polylines).', "click", function() {
531
					'.$polyline['onclick'].'
532
				});
533
				';
534
            }
535 View Code Duplication
            if ($polyline['ondblclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
536
                $polyline_output .= '
537
				google.maps.event.addListener(polyline_'.count($this->polylines).', "dblclick", function() {
538
					'.$polyline['ondblclick'].'
539
				});
540
				';
541
            }
542 View Code Duplication
            if ($polyline['onmousedown'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
543
                $polyline_output .= '
544
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mousedown", function() {
545
					'.$polyline['onmousedown'].'
546
				});
547
				';
548
            }
549 View Code Duplication
            if ($polyline['onmousemove'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
550
                $polyline_output .= '
551
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mousemove", function() {
552
					'.$polyline['onmousemove'].'
553
				});
554
				';
555
            }
556 View Code Duplication
            if ($polyline['onmouseout'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
557
                $polyline_output .= '
558
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseout", function() {
559
					'.$polyline['onmouseout'].'
560
				});
561
				';
562
            }
563 View Code Duplication
            if ($polyline['onmouseover'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
564
                $polyline_output .= '
565
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseover", function() {
566
					'.$polyline['onmouseover'].'
567
				});
568
				';
569
            }
570 View Code Duplication
            if ($polyline['onmouseup'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
571
                $polyline_output .= '
572
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseup", function() {
573
					'.$polyline['onmouseup'].'
574
				});
575
				';
576
            }
577 View Code Duplication
            if ($polyline['onrightclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
578
                $polyline_output .= '
579
				google.maps.event.addListener(polyline_'.count($this->polylines).', "rightclick", function() {
580
					'.$polyline['onrightclick'].'
581
				});
582
				';
583
            }
584
585
            array_push($this->polylines, $polyline_output);
586
        }
587
    }
588
589
    public function add_polygon($params = array())
590
    {
591
        $polygon = array();
592
593
        $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
594
        $polygon['clickable'] = true;                            // Defines if the polygon is clickable
595
        $polygon['strokeColor'] = '#FF0000';                    // The hex value of the polygons border color
596
        $polygon['strokeOpacity'] = '0.8';                        // The opacity of the polygon border. 0 to 1.0
597
        $polygon['strokeWeight'] = '2';                            // The thickness of the polygon border
598
        $polygon['fillColor'] = '#FF0000';                        // The hex value of the polygons fill color
599
        $polygon['fillOpacity'] = '0.3';                        // The opacity of the polygons fill
600
        $polygon['onclick'] = '';                                // JavaScript performed when a polygon is clicked
601
        $polygon['ondblclick'] = '';                            // JavaScript performed when a polygon is double-clicked
602
        $polygon['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a polygon
603
        $polygon['onmousemove'] = '';                            // JavaScript performed when the mouse moves in the area of the polygon
604
        $polygon['onmouseout'] = '';                            // JavaScript performed when the mouse leaves the area of the polygon
605
        $polygon['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the polygon
606
        $polygon['onmouseup'] = '';                                // JavaScript performed when a mouseup event occurs on a polygon
607
        $polygon['onrightclick'] = '';                            // JavaScript performed when a right-click occurs on a polygon
608
        $polygon['zIndex'] = '';                                // The zIndex of the polygon. If two polygons overlap, the polygon with the higher zIndex will appear on top
609
610
        $polygon_output = '';
611
612
        foreach ($params as $key => $value) {
613
            if (isset($polygon[$key])) {
614
                $polygon[$key] = $value;
615
            }
616
        }
617
618
        if (count($polygon['points'])) {
619
            $polygon_output .= '
620
				var polygon_plan_'.count($this->polygons).' = [';
621
            $i = 0;
622
            $lat_long_output = '';
623 View Code Duplication
            foreach ($polygon['points'] as $point) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
624
                if ($i > 0) {
625
                    $polygon_output .= ',';
626
                }
627
                $lat_long_to_push = '';
628
                if ($this->is_lat_long($point)) {
629
                    $lat_long_to_push = $point;
630
                    $polygon_output .= '
631
					new google.maps.LatLng('.$point.')
632
					';
633
                } else {
634
                    $lat_long = $this->get_lat_long_from_address($point);
635
                    $polygon_output .= '
636
					new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
637
                    $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
638
                }
639
                $lat_long_output .= '
640
					lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
641
				';
642
                $i++;
643
            }
644
            $polygon_output .= '];';
645
646
            $polygon_output .= $lat_long_output;
647
        }
648
649
        $polygon_output .= '
650
			var polygon_'.count($this->polygons).' = new google.maps.Polygon({
651
    			';
652
        if (count($polygon['points'])) {
653
            $polygon_output .= 'path: polygon_plan_'.count($this->polygons).',
654
					';
655
        }
656
        $polygon_output .= '
657
    			strokeColor: "'.$polygon['strokeColor'].'",
658
    			strokeOpacity: '.$polygon['strokeOpacity'].',
659
    			strokeWeight: '.$polygon['strokeWeight'].',
660
				fillColor: "'.$polygon['fillColor'].'",
661
				fillOpacity: '.$polygon['fillOpacity'];
662
        if (!$polygon['clickable']) {
663
            $polygon_output .= ',
664
				clickable: false';
665
        }
666
        if ($polygon['zIndex'] != "" && is_numeric($polygon['zIndex'])) {
667
            $polygon_output .= ',
668
				zIndex: '.$polygon['zIndex'];
669
        }
670
        $polygon_output .= '
671
			});
672
673
			polygon_'.count($this->polygons).'.setMap('.$this->map_name.');
674
675
		';
676
677 View Code Duplication
        if ($polygon['onclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
678
            $polygon_output .= '
679
			google.maps.event.addListener(polygon_'.count($this->polygons).', "click", function() {
680
				'.$polygon['onclick'].'
681
			});
682
			';
683
        }
684 View Code Duplication
        if ($polygon['ondblclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
685
            $polygon_output .= '
686
			google.maps.event.addListener(polygon_'.count($this->polygons).', "dblclick", function() {
687
				'.$polygon['ondblclick'].'
688
			});
689
			';
690
        }
691 View Code Duplication
        if ($polygon['onmousedown'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
692
            $polygon_output .= '
693
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mousedown", function() {
694
				'.$polygon['onmousedown'].'
695
			});
696
			';
697
        }
698 View Code Duplication
        if ($polygon['onmousemove'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
699
            $polygon_output .= '
700
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mousemove", function() {
701
				'.$polygon['onmousemove'].'
702
			});
703
			';
704
        }
705 View Code Duplication
        if ($polygon['onmouseout'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
706
            $polygon_output .= '
707
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseout", function() {
708
				'.$polygon['onmouseout'].'
709
			});
710
			';
711
        }
712 View Code Duplication
        if ($polygon['onmouseover'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
713
            $polygon_output .= '
714
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseover", function() {
715
				'.$polygon['onmouseover'].'
716
			});
717
			';
718
        }
719 View Code Duplication
        if ($polygon['onmouseup'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
720
            $polygon_output .= '
721
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseup", function() {
722
				'.$polygon['onmouseup'].'
723
			});
724
			';
725
        }
726 View Code Duplication
        if ($polygon['onrightclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
727
            $polygon_output .= '
728
			google.maps.event.addListener(polygon_'.count($this->polygons).', "rightclick", function() {
729
				'.$polygon['onrightclick'].'
730
			});
731
			';
732
        }
733
734
        array_push($this->polygons, $polygon_output);
735
    }
736
737
    public function add_circle($params = array())
738
    {
739
        $circle = array();
740
741
        $circle['center'] = '';                                    // The center position (latitude/longitude coordinate OR addresse) at which the circle will appear
742
        $circle['clickable'] = true;                            // Defines if the circle is clickable
743
        $circle['radius'] = 0;                                    // The circle radius (in metres)
744
        $circle['strokeColor'] = '0.8';                            // The hex value of the circles border color
745
        $circle['strokeOpacity'] = '0.8';                        // The opacity of the circle border
746
        $circle['strokeWeight'] = '2';                            // The thickness of the circle border
747
        $circle['fillColor'] = '#FF0000';                        // The hex value of the circles fill color
748
        $circle['fillOpacity'] = '0.3';                            // The opacity of the circles fill
749
        $circle['onclick'] = '';                                // JavaScript performed when a circle is clicked
750
        $circle['ondblclick'] = '';                                // JavaScript performed when a circle is double-clicked
751
        $circle['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a circle
752
        $circle['onmousemove'] = '';                            // JavaScript performed when the mouse moves in the area of the circle
753
        $circle['onmouseout'] = '';                                // JavaScript performed when the mouse leaves the area of the circle
754
        $circle['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the circle
755
        $circle['onmouseup'] = '';                                // JavaScript performed when a mouseup event occurs on a circle
756
        $circle['onrightclick'] = '';                            // JavaScript performed when a right-click occurs on a circle
757
        $circle['zIndex'] = '';                                    // The zIndex of the circle. If two circles overlap, the circle with the higher zIndex will appear on top
758
759
        $circle_output = '';
760
761
        foreach ($params as $key => $value) {
762
            if (isset($circle[$key])) {
763
                $circle[$key] = $value;
764
            }
765
        }
766
767
        if ($circle['radius'] > 0 && $circle['center'] != "") {
768
            $lat_long_to_push = '';
769 View Code Duplication
            if ($this->is_lat_long($circle['center'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
770
                $lat_long_to_push = $circle['center'];
771
                $circle_output = '
772
				var circleCenter = new google.maps.LatLng('.$circle['center'].')
773
				';
774
            } else {
775
                $lat_long = $this->get_lat_long_from_address($circle['center']);
776
                $circle_output = '
777
				var circleCenter = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
778
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
779
            }
780
            $circle_output .= '
781
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
782
			';
783
784
            $circle_output .= '
785
				var circleOptions = {
786
					strokeColor: "'.$circle['strokeColor'].'",
787
					strokeOpacity: '.$circle['strokeOpacity'].',
788
					strokeWeight: '.$circle['strokeWeight'].',
789
					fillColor: "'.$circle['fillColor'].'",
790
					fillOpacity: '.$circle['fillOpacity'].',
791
					map: '.$this->map_name.',
792
					center: circleCenter,
793
					radius: '.$circle['radius'];
794
            if (!$circle['clickable']) {
795
                $circle_output .= ',
796
					clickable: false';
797
            }
798
            if ($circle['zIndex'] != "" && is_numeric($circle['zIndex'])) {
799
                $circle_output .= ',
800
					zIndex: '.$circle['zIndex'];
801
            }
802
            $circle_output .= '
803
				};
804
				var circle_'.count($this->circles).' = new google.maps.Circle(circleOptions);
805
			';
806
807 View Code Duplication
            if ($circle['onclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
808
                $circle_output .= '
809
				google.maps.event.addListener(circle_'.count($this->circles).', "click", function() {
810
					'.$circle['onclick'].'
811
				});
812
				';
813
            }
814 View Code Duplication
            if ($circle['ondblclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
815
                $circle_output .= '
816
				google.maps.event.addListener(circle_'.count($this->circles).', "dblclick", function() {
817
					'.$circle['ondblclick'].'
818
				});
819
				';
820
            }
821 View Code Duplication
            if ($circle['onmousedown'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
822
                $circle_output .= '
823
				google.maps.event.addListener(circle_'.count($this->circles).', "mousedown", function() {
824
					'.$circle['onmousedown'].'
825
				});
826
				';
827
            }
828 View Code Duplication
            if ($circle['onmousemove'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
829
                $circle_output .= '
830
				google.maps.event.addListener(circle_'.count($this->circles).', "mousemove", function() {
831
					'.$circle['onmousemove'].'
832
				});
833
				';
834
            }
835 View Code Duplication
            if ($circle['onmouseout'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
836
                $circle_output .= '
837
				google.maps.event.addListener(circle_'.count($this->circles).', "mouseout", function() {
838
					'.$circle['onmouseout'].'
839
				});
840
				';
841
            }
842 View Code Duplication
            if ($circle['onmouseover'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
843
                $circle_output .= '
844
				google.maps.event.addListener(circle_'.count($this->circles).', "mouseover", function() {
845
					'.$circle['onmouseover'].'
846
				});
847
				';
848
            }
849 View Code Duplication
            if ($circle['onmouseup'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
850
                $circle_output .= '
851
				google.maps.event.addListener(circle_'.count($this->circles).', "mouseup", function() {
852
					'.$circle['onmouseup'].'
853
				});
854
				';
855
            }
856 View Code Duplication
            if ($circle['onrightclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
857
                $circle_output .= '
858
				google.maps.event.addListener(circle_'.count($this->circles).', "rightclick", function() {
859
					'.$circle['onrightclick'].'
860
				});
861
				';
862
            }
863
864
            array_push($this->circles, $circle_output);
865
        }
866
    }
867
868
    public function add_rectangle($params = array())
869
    {
870
        $rectangle = array();
871
872
        $rectangle['positionSW'] = '';                            // The South-West position (latitude/longitude coordinate OR address) at which the rectangle will appear
873
        $rectangle['positionNE'] = '';                            // The North-East position(latitude/longitude coordinate OR address) at which the rectangle will appear
874
        $rectangle['clickable'] = true;                            // Defines if the rectangle is clickable
875
        $rectangle['strokeColor'] = '0.8';                        // The hex value of the rectangles border color
876
        $rectangle['strokeOpacity'] = '0.8';                    // The opacity of the rectangle border
877
        $rectangle['strokeWeight'] = '2';                        // The thickness of the rectangle border
878
        $rectangle['fillColor'] = '#FF0000';                    // The hex value of the rectangles fill color
879
        $rectangle['fillOpacity'] = '0.3';                        // The opacity of the rectangles fill
880
        $rectangle['onclick'] = '';                                // JavaScript performed when a rectangle is clicked
881
        $rectangle['ondblclick'] = '';                            // JavaScript performed when a rectangle is double-clicked
882
        $rectangle['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a rectangle
883
        $rectangle['onmousemove'] = '';                            // JavaScript performed when the mouse moves in the area of the rectangle
884
        $rectangle['onmouseout'] = '';                            // JavaScript performed when the mouse leaves the area of the rectangle
885
        $rectangle['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the rectangle
886
        $rectangle['onmouseup'] = '';                            // JavaScript performed when a mouseup event occurs on a rectangle
887
        $rectangle['onrightclick'] = '';                        // JavaScript performed when a right-click occurs on a rectangle
888
        $rectangle['zIndex'] = '';                                // The zIndex of the rectangle. If two rectangles overlap, the rectangle with the higher zIndex will appear on top
889
890
        $rectangle_output = '';
891
892
        foreach ($params as $key => $value) {
893
            if (isset($rectangle[$key])) {
894
                $rectangle[$key] = $value;
895
            }
896
        }
897
898
        if ($rectangle['positionSW'] != "" && $rectangle['positionNE'] != "") {
899
            $lat_long_to_push = '';
900 View Code Duplication
            if ($this->is_lat_long($rectangle['positionSW'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
901
                $lat_long_to_push = $rectangle['positionSW'];
902
                $rectangle_output .= '
903
				var positionSW = new google.maps.LatLng('.$rectangle['positionSW'].')
904
				';
905
            } else {
906
                $lat_long = $this->get_lat_long_from_address($rectangle['positionSW']);
907
                $rectangle_output .= '
908
				var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
909
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
910
            }
911
            $rectangle_output .= '
912
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
913
			';
914
915
            $lat_long_to_push = '';
916 View Code Duplication
            if ($this->is_lat_long($rectangle['positionNE'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
917
                $lat_long_to_push = $rectangle['positionNE'];
918
                $rectangle_output .= '
919
				var positionNE = new google.maps.LatLng('.$rectangle['positionNE'].')
920
				';
921
            } else {
922
                $lat_long = $this->get_lat_long_from_address($rectangle['positionNE']);
923
                $rectangle_output .= '
924
				var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
925
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
926
            }
927
            $rectangle_output .= '
928
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
929
			';
930
931
            $rectangle_output .= '
932
				var rectangleOptions = {
933
					strokeColor: "'.$rectangle['strokeColor'].'",
934
					strokeOpacity: '.$rectangle['strokeOpacity'].',
935
					strokeWeight: '.$rectangle['strokeWeight'].',
936
					fillColor: "'.$rectangle['fillColor'].'",
937
					fillOpacity: '.$rectangle['fillOpacity'].',
938
					map: '.$this->map_name.',
939
					bounds: new google.maps.LatLngBounds(positionSW, positionNE)';
940
            if (!$rectangle['clickable']) {
941
                $rectangle_output .= ',
942
					clickable: false';
943
            }
944
            if ($rectangle['zIndex'] != "" && is_numeric($rectangle['zIndex'])) {
945
                $rectangle_output .= ',
946
					zIndex: '.$rectangle['zIndex'];
947
            }
948
            $rectangle_output .= '
949
				};';
950
951
            $rectangle_output .= '
952
				var rectangle_'.count($this->rectangles).' = new google.maps.Rectangle(rectangleOptions);
953
			';
954
955 View Code Duplication
            if ($rectangle['onclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
956
                $rectangle_output .= '
957
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "click", function() {
958
					'.$rectangle['onclick'].'
959
				});
960
				';
961
            }
962 View Code Duplication
            if ($rectangle['ondblclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
963
                $rectangle_output .= '
964
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "dblclick", function() {
965
					'.$rectangle['ondblclick'].'
966
				});
967
				';
968
            }
969 View Code Duplication
            if ($rectangle['onmousedown'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
970
                $rectangle_output .= '
971
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousedown", function() {
972
					'.$rectangle['onmousedown'].'
973
				});
974
				';
975
            }
976 View Code Duplication
            if ($rectangle['onmousemove'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
977
                $rectangle_output .= '
978
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousemove", function() {
979
					'.$rectangle['onmousemove'].'
980
				});
981
				';
982
            }
983 View Code Duplication
            if ($rectangle['onmouseout'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
984
                $rectangle_output .= '
985
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseout", function() {
986
					'.$rectangle['onmouseout'].'
987
				});
988
				';
989
            }
990 View Code Duplication
            if ($rectangle['onmouseover'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
991
                $rectangle_output .= '
992
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseover", function() {
993
					'.$rectangle['onmouseover'].'
994
				});
995
				';
996
            }
997 View Code Duplication
            if ($rectangle['onmouseup'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
998
                $rectangle_output .= '
999
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseup", function() {
1000
					'.$rectangle['onmouseup'].'
1001
				});
1002
				';
1003
            }
1004 View Code Duplication
            if ($rectangle['onrightclick'] != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1005
                $rectangle_output .= '
1006
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "rightclick", function() {
1007
					'.$rectangle['onrightclick'].'
1008
				});
1009
				';
1010
            }
1011
1012
            array_push($this->rectangles, $rectangle_output);
1013
        }
1014
    }
1015
1016
    public function add_ground_overlay($params = array())
1017
    {
1018
        $overlay = array();
1019
1020
        $overlay['image'] = '';                                    // JavaScript performed when a ground overlay is clicked
1021
        $overlay['positionSW'] = '';                            // The South-West position (latitude/longitude coordinate OR addresse) at which the ground overlay will appear
1022
        $overlay['positionNE'] = '';                            // The North-East position (latitude/longitude coordinate OR addresse) at which the ground overlay will appear
1023
        $overlay['clickable'] = true;                            // Defines if the ground overlay is clickable
1024
        $overlay['onclick'] = '';                                // JavaScript performed when a ground overlay is clicked
1025
1026
        $overlay_output = '';
1027
1028
        foreach ($params as $key => $value) {
1029
            if (isset($overlay[$key])) {
1030
                $overlay[$key] = $value;
1031
            }
1032
        }
1033
1034
        if ($overlay['image'] != "" && $overlay['positionSW'] != "" && $overlay['positionNE'] != "") {
1035
            $lat_long_to_push = '';
1036 View Code Duplication
            if ($this->is_lat_long($overlay['positionSW'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1037
                $lat_long_to_push = $overlay['positionSW'];
1038
                $overlay_output .= '
1039
				var positionSW = new google.maps.LatLng('.$overlay['positionSW'].')
1040
				';
1041
            } else {
1042
                $lat_long = $this->get_lat_long_from_address($overlay['positionSW']);
1043
                $overlay_output .= '
1044
				var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
1045
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
1046
            }
1047
            $overlay_output .= '
1048
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
1049
			';
1050
1051
            $lat_long_to_push = '';
1052 View Code Duplication
            if ($this->is_lat_long($overlay['positionNE'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1053
                $lat_long_to_push = $overlay['positionNE'];
1054
                $overlay_output .= '
1055
				var positionNE = new google.maps.LatLng('.$overlay['positionNE'].')
1056
				';
1057
            } else {
1058
                $lat_long = $this->get_lat_long_from_address($overlay['positionNE']);
1059
                $overlay_output .= '
1060
				var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
1061
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
1062
            }
1063
            $overlay_output .= '
1064
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
1065
			';
1066
1067
            $overlay_output .= '
1068
				var overlay_'.count($this->overlays).' = new google.maps.GroundOverlay("'.$overlay['image'].'", new google.maps.LatLngBounds(positionSW, positionNE), { map: '.$this->map_name;
1069
            if (!$overlay['clickable']) {
1070
                $overlay_output .= ', clickable: false';
1071
            }
1072
            $overlay_output .= '});
1073
			';
1074
1075
            if ($overlay['onclick'] != "") {
1076
                $overlay_output .= '
1077
				google.maps.event.addListener(overlay_'.count($this->overlays).', "click", function() {
1078
					'.$overlay['onclick'].'
1079
				});
1080
				';
1081
            }
1082
1083
            array_push($this->overlays, $overlay_output);
1084
        }
1085
    }
1086
1087
    public function create_map()
1088
    {
1089
        $this->output_js = '';
1090
        $this->output_js_contents = '';
1091
        $this->output_html = '';
1092
1093
        if ($this->maps_loaded == 0) {
1094
            if ($this->apiKey != "") {
1095
                $apiLocation = 'https://maps.googleapis.com/maps/api/js?key='.$this->apiKey.'&';
1096
            } else {
1097
                $apiLocation = 'https://maps.google.com/maps/api/js?';
1098
            }
1099
            if ($this->region != "" && strlen($this->region) == 2) {
1100
                $apiLocation .= '&region='.strtoupper($this->region);
1101
            }
1102
            if ($this->language != "") {
1103
                $apiLocation .= '&language='.$this->language;
1104
            }
1105
            $libraries = array();
1106
            if ($this->adsense != "") {
1107
                array_push($libraries, 'adsense');
1108
            }
1109
            if ($this->places != "") {
1110
                array_push($libraries, 'places');
1111
            }
1112
            if ($this->panoramio) {
1113
                array_push($libraries, 'panoramio');
1114
            }
1115
            if ($this->drawing) {
1116
                array_push($libraries, 'drawing');
1117
            }
1118
            if (count($libraries)) {
1119
                $apiLocation .= '&libraries='.implode(",", $libraries);
1120
            }
1121
1122
            if (!$this->loadAsynchronously) {
1123
                $this->output_js .= '
1124
				<script type="text/javascript" src="'.$apiLocation.'"></script>';
1125
            }
1126
1127
            if ($this->cluster) {
1128
                $this->output_js .= '
1129
1130
			<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-marker-clusterer/1.0.0/markerclusterer_compiled.js"></script >
1131
					';
1132
            }
1133
        }
1134
        if ($this->jsfile == "") {
1135
            $this->output_js .= '
1136
			<script type="text/javascript">
1137
			//<![CDATA[
1138
			';
1139
        }
1140
1141
        $this->output_js_contents .= '
1142
			var '.$this->map_name.'; // Global declaration of the map
1143
			var lat_longs_'.$this->map_name.' = new Array();
1144
			var markers_'.$this->map_name.' = new Array();
1145
            var iw_'.$this->map_name.';
1146
			';
1147
        if ($this->cluster) {
1148
            $this->output_js_contents .= 'var markerCluster;
1149
			';
1150
        }
1151
        if ($this->directions) {
1152
            $rendererOptions = '';
1153
            if ($this->directionsDraggable) {
1154
                $this->output_js_contents .= '
1155
			var rendererOptions = { draggable: true };
1156
			';
1157
                $rendererOptions = 'rendererOptions';
1158
            }
1159
            $this->output_js_contents .= 'var directionsDisplay = new google.maps.DirectionsRenderer('.$rendererOptions.');
1160
			var directionsService = new google.maps.DirectionsService();
1161
			';
1162
        }
1163
        if ($this->places) {
1164
            $this->output_js_contents .= 'var placesService;
1165
			';
1166
            if ($this->placesAutocompleteInputID != "") {
1167
                $this->output_js_contents .= 'var placesAutocomplete;
1168
			';
1169
            }
1170
        }
1171
        if ($this->adsense) {
1172
            $this->output_js_contents .= 'var adUnit;
1173
			';
1174
        }
1175
        if ($this->drawing) {
1176
            $this->output_js_contents .= 'var drawingManager;
1177
			';
1178
        }
1179
1180
        $this->output_js_contents .= '
1181
			iw_'.$this->map_name.' = new google.maps.InfoWindow(';
1182
        if ($this->infowindowMaxWidth != 0) {
1183
            $this->output_js_contents .= '{
1184
				maxWidth: '.$this->infowindowMaxWidth.'
1185
			}';
1186
        }
1187
        $this->output_js_contents .= ');
1188
1189
				 ';
1190
1191
        $this->output_js_contents .= 'function initialize_'.$this->map_name.'() {
1192
1193
				';
1194
1195
        $styleOutput = '';
1196
        if (count($this->styles)) {
1197
            $styles = 0;
1198
            foreach ($this->styles as $style) {
1199
                $this->output_js_contents .= 'var styles_'.$styles.' = '.json_encode($style['definition']).';
1200
				';
1201
1202
                if ($this->stylesAsMapTypes) {
1203
                    $this->output_js_contents .= 'var styles_'.$styles.' = new google.maps.StyledMapType(styles_'.$styles.', {name:"'.$style['name'].'"});
1204
				';
1205
                } else {
1206
                    $styleOutput .= $this->map_name.'.setOptions({styles: styles_'.$styles.'});
1207
				';
1208
                    break;
1209
                }
1210
1211
                ++$styles;
1212
            }
1213
        }
1214
1215 View Code Duplication
        if ($this->center != "auto") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1216
            if ($this->is_lat_long($this->center)) { // if centering the map on a lat/long
1217
                $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$this->center.');';
1218
            } else {  // if centering the map on an address
1219
                $lat_long = $this->get_lat_long_from_address($this->center);
1220
                $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');';
1221
            }
1222
        }
1223
1224
        $this->output_js_contents .= '
1225
				var myOptions = {
1226
			  		';
1227
        if ($this->zoom == "auto") {
1228
            $this->output_js_contents .= 'zoom: 13,';
1229
        } else {
1230
            $this->output_js_contents .= 'zoom: '.$this->zoom.',';
1231
        }
1232
        if ($this->center != "auto") {
1233
            $this->output_js_contents .= '
1234
					center: myLatlng,';
1235
        }
1236
        if($this->gestureHandling != 'auto'){
1237
            $this->output_js_contents .= '
1238
                    gestureHandling: \''.$this->gestureHandling .'\',';
1239
        }
1240
        if (strtolower($this->map_type) == "street") {
1241
            $map_type = "ROADMAP";
1242
        } else {
1243
            $map_type = $this->map_type;
1244
        }
1245
        $this->output_js_contents .= '
1246
			  		mapTypeId: google.maps.MapTypeId.'.$map_type;
1247
        if ($this->backgroundColor) {
1248
            $this->output_js_contents .= ',
1249
					backgroundColor: \''.$this->backgroundColor.'\'';
1250
        }
1251
        if ($this->disableDefaultUI) {
1252
            $this->output_js_contents .= ',
1253
					disableDefaultUI: true';
1254
        }
1255
        if ($this->disableMapTypeControl) {
1256
            $this->output_js_contents .= ',
1257
					mapTypeControl: false';
1258
        }
1259
        if ($this->disableNavigationControl) {
1260
            $this->output_js_contents .= ',
1261
					navigationControl: false';
1262
        }
1263
        if ($this->disableScaleControl) {
1264
            $this->output_js_contents .= ',
1265
					scaleControl: false';
1266
        }
1267
        if ($this->disableStreetViewControl) {
1268
            $this->output_js_contents .= ',
1269
					streetViewControl: false';
1270
        }
1271
        if ($this->disableDoubleClickZoom) {
1272
            $this->output_js_contents .= ',
1273
					disableDoubleClickZoom: true';
1274
        }
1275
        if (!$this->draggable) {
1276
            $this->output_js_contents .= ',
1277
					draggable: false';
1278
        }
1279
        if ($this->draggableCursor != "") {
1280
            $this->output_js_contents .= ',
1281
					draggableCursor: "'.$this->draggableCursor.'"';
1282
        }
1283
        if ($this->draggingCursor != "") {
1284
            $this->output_js_contents .= ',
1285
					draggingCursor: "'.$this->draggingCursor.'"';
1286
        }
1287
        if (!$this->keyboardShortcuts) {
1288
            $this->output_js_contents .= ',
1289
					keyboardShortcuts: false';
1290
        }
1291
        $mapTypeControlOptions = array();
1292
        $map_types = array();
1293
        if ($this->mapTypeControlPosition != "") {
1294
            array_push($mapTypeControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->mapTypeControlPosition));
1295
        }
1296
        if ($this->mapTypeControlStyle != "" && (strtoupper($this->mapTypeControlStyle) == "DROPDOWN_MENU" || strtoupper($this->mapTypeControlStyle) == "HORIZONTAL_BAR")) {
1297
            array_push($mapTypeControlOptions, 'style: google.maps.MapTypeControlStyle.'.strtoupper($this->mapTypeControlStyle));
1298
        }
1299
        if (count($this->map_types_available)) {
1300
            foreach ($this->map_types_available as $map_type) {
1301
                array_push($map_types, 'google.maps.MapTypeId.'.strtoupper($map_type));
1302
            }
1303
        }
1304
        if (count($this->styles) && $this->stylesAsMapTypes) {
1305
            $styles = 0;
1306
            foreach ($this->styles as $style) {
1307
                array_push($map_types, '"style'.$styles.'"');
1308
                $styleOutput .= '
1309
					  '.$this->map_name.'.mapTypes.set("style'.$styles.'", styles_'.$styles.');
1310
				';
1311
                if ($this->stylesAsMapTypesDefault == $style['name']) {
1312
                    $styleOutput .= '
1313
					  '.$this->map_name.'.setMapTypeId("style'.$styles.'");
1314
				';
1315
                }
1316
                $styles++;
1317
            }
1318
        }
1319
        if (count($map_types)) {
1320
            array_push($mapTypeControlOptions, 'mapTypeIds: ['.implode(", ", $map_types).']');
1321
        }
1322
        if (count($mapTypeControlOptions)) {
1323
            $this->output_js_contents .= ',
1324
					mapTypeControlOptions: {'.implode(",", $mapTypeControlOptions).'}';
1325
        }
1326
        if ($this->minzoom != "") {
1327
            $this->output_js_contents .= ',
1328
					minZoom: '.$this->minzoom;
1329
        }
1330
        if ($this->maxzoom != "") {
1331
            $this->output_js_contents .= ',
1332
					maxZoom: '.$this->maxzoom;
1333
        }
1334
        if ($this->noClear) {
1335
            $this->output_js_contents .= ',
1336
					noClear: true';
1337
        }
1338
        if ($this->navigationControlPosition != "") {
1339
            $this->output_js_contents .= ',
1340
					navigationControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->navigationControlPosition).'}';
1341
        }
1342
        if ($this->scaleControlPosition != "") {
1343
            $this->output_js_contents .= ',
1344
			         scaleControl: true,
1345
					scaleControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->scaleControlPosition).'}';
1346
        }
1347
        if (!$this->scrollwheel) {
1348
            $this->output_js_contents .= ',
1349
					scrollwheel: false';
1350
        }
1351
        if ($this->streetViewControlPosition != "") {
1352
            $this->output_js_contents .= ',
1353
					streetViewControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->streetViewControlPosition).'}';
1354
        }
1355
        if ($this->tilt == 45) {
1356
            $this->output_js_contents .= ',
1357
					tilt: '.$this->tilt;
1358
        }
1359
        $zoomControlOptions = array();
1360
        if ($this->zoomControlPosition != "") {
1361
            array_push($zoomControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->zoomControlPosition));
1362
        }
1363
        if ($this->zoomControlStyle != "" && (strtoupper($this->zoomControlStyle) == "SMALL" || strtoupper($this->zoomControlStyle) == "LARGE")) {
1364
            array_push($zoomControlOptions, 'style: google.maps.ZoomControlStyle.'.strtoupper($this->zoomControlStyle));
1365
        }
1366
        if (count($zoomControlOptions)) {
1367
            $this->output_js_contents .= ',
1368
					zoomControlOptions: {'.implode(",", $zoomControlOptions).'}';
1369
        }
1370
1371
1372
        $this->output_js_contents .= '};';
1373
1374
        $this->output_js_contents .=$this->map_name.' = new google.maps.Map(document.getElementById("'.$this->map_div_id.'"), myOptions);';
1375
1376
        if ($styleOutput != "") {
1377
            $this->output_js_contents .= $styleOutput.'
1378
				';
1379
        }
1380
1381
        if ($this->trafficOverlay) {
1382
            $this->output_js_contents .= 'var trafficLayer = new google.maps.TrafficLayer();
1383
				trafficLayer.setMap('.$this->map_name.');
1384
				';
1385
        }
1386
        if ($this->bicyclingOverlay) {
1387
            $this->output_js_contents .= 'var bikeLayer = new google.maps.BicyclingLayer();
1388
				bikeLayer.setMap('.$this->map_name.');
1389
				';
1390
        }
1391
1392
        if ((is_array($this->kmlLayerURL) && count($this->kmlLayerURL)) || (!is_array($this->kmlLayerURL) && $this->kmlLayerURL != "")) {
1393
            if (!is_array($this->kmlLayerURL)) {
1394
                // Need to convert single KML layer to array
1395
                $this->kmlLayerURL = array($this->kmlLayerURL);
1396
            }
1397
            if (count($this->kmlLayerURL)) {
1398
                $i = 0;
1399
                foreach ($this->kmlLayerURL as $kmlLayerURL) {
1400
                    $this->output_js_contents .= '
1401
						var kmlLayerOptions = {
1402
							map: '.$this->map_name;
1403
                    if ($this->kmlLayerPreserveViewport) {
1404
                        $this->output_js_contents .= ',
1405
							preserveViewport: true';
1406
                    }
1407
                    $this->output_js_contents .= '
1408
						}
1409
						var kmlLayer_'.$i.' = new google.maps.KmlLayer("'.$kmlLayerURL.'", kmlLayerOptions);
1410
						';
1411
                    ++$i;
1412
                }
1413
            }
1414
        }
1415
1416
        if ($this->panoramio) {
1417
            $this->output_js_contents .= 'var panoramioLayer = new google.maps.panoramio.PanoramioLayer();
1418
				';
1419
            if ($this->panoramioTag != "") {
1420
                $this->output_js_contents .= 'panoramioLayer.setTag("'.$this->panoramioTag.'");
1421
				';
1422
            }
1423
            if ($this->panoramioUser != "") {
1424
                $this->output_js_contents .= 'panoramioLayer.setUserId("'.$this->panoramioUser.'");
1425
				';
1426
            }
1427
            $this->output_js_contents .= '
1428
				panoramioLayer.setMap('.$this->map_name.');
1429
				';
1430
        }
1431
1432
        if (strtolower($this->map_type) == "street") { // if defaulting the map to Street View
1433
            $this->output_js_contents .= '
1434
			  	var streetViewOptions = {
1435
			    	position: myLatlng';
1436
            if (!$this->streetViewAddressControl) {
1437
                $this->output_js_contents .= ',
1438
					addressControl: false';
1439
            }
1440
            if ($this->streetViewAddressPosition != "") {
1441
                $this->output_js_contents .= ',
1442
					addressControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewAddressPosition.' }';
1443
            }
1444
            if ($this->streetViewCloseButton) {
1445
                $this->output_js_contents .= ',
1446
					enableCloseButton: true';
1447
            }
1448
            if (!$this->streetViewLinksControl) {
1449
                $this->output_js_contents .= ',
1450
					linksControl: false';
1451
            }
1452
            if (!$this->streetViewPanControl) {
1453
                $this->output_js_contents .= ',
1454
					panControl: false';
1455
            }
1456
            if ($this->streetViewPanPosition != "") {
1457
                $this->output_js_contents .= ',
1458
					panControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewPanPosition.' }';
1459
            }
1460
            if ($this->streetViewPovHeading != 0 || $this->streetViewPovPitch != 0 || $this->streetViewPovZoom != 0) {
1461
                $this->output_js_contents .= ',
1462
					pov: {
1463
						heading: '.$this->streetViewPovHeading.',
1464
						pitch: '.$this->streetViewPovPitch.',
1465
						zoom: '.$this->streetViewPovZoom.'
1466
					}';
1467
            }
1468
            if (!$this->streetViewZoomControl) {
1469
                $this->output_js_contents .= ',
1470
					zoomControl: false';
1471
            }
1472
            if ($this->streetViewZoomPosition != "" || $this->streetViewZoomStyle != "") {
1473
                $this->output_js_contents .= ',
1474
					zoomControlOptions: {';
1475
                if ($this->streetViewZoomPosition != "") {
1476
                    $this->output_js_contents .= '
1477
						position: google.maps.ControlPosition.'.$this->streetViewZoomPosition.',';
1478
                }
1479
                if ($this->streetViewZoomStyle != "") {
1480
                    $this->output_js_contents .= '
1481
						style: google.maps.ZoomControlStyle.'.$this->streetViewZoomStyle.',';
1482
                }
1483
                $this->output_js_contents = trim($this->output_js_contents, ",");
1484
                $this->output_js_contents .= '}';
1485
            }
1486
            $this->output_js_contents .= '
1487
				};
1488
				var streetView = new google.maps.StreetViewPanorama(document.getElementById("'.$this->map_div_id.'"), streetViewOptions);
1489
				streetView.setVisible(true);
1490
	      		';
1491
        }
1492
1493
        if ($this->center == "auto") { // if wanting to center on the users location
1494
            $this->output_js_contents .= '
1495
				// Try W3C Geolocation (Preferred)
1496
				if(navigator.geolocation) {
1497
					navigator.geolocation.getCurrentPosition(function(position) {
1498
						'.$this->map_name.'.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
1499
					}, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1500
				// Browser doesn\'t support Geolocation
1501
				}else{
1502
					alert(\'Your browser does not support geolocation.\');
1503
				}
1504
			';
1505
        }
1506
1507
        if ($this->directions) {
1508
            $this->output_js_contents .= 'directionsDisplay.setMap('.$this->map_name.');
1509
			';
1510
            if ($this->directionsDivID != "") {
1511
                $this->output_js_contents .= 'directionsDisplay.setPanel(document.getElementById("'.$this->directionsDivID.'"));
1512
			';
1513
            }
1514
            if ($this->directionsDraggable && $this->directionsChanged != "") {
1515
                $this->output_js_contents .= 'google.maps.event.addListener(directionsDisplay, "directions_changed", function() {
1516
					'.$this->directionsChanged.'
1517
				});
1518
			';
1519
            }
1520
        }
1521
1522
        if ($this->drawing) {
1523
            if ($this->drawingControlPosition == '') {
1524
                $this->drawingControlPosition = 'TOP_CENTER';
1525
            }
1526
1527
            $this->output_js_contents .= 'drawingManager = new google.maps.drawing.DrawingManager({
1528
				drawingMode: google.maps.drawing.OverlayType.'.strtoupper($this->drawingDefaultMode).',
1529
  				drawingControl: '.(!$this->drawingControl ? 'false' : 'true').',
1530
  				drawingControlOptions: {
1531
  					position: google.maps.ControlPosition.'.strtoupper($this->drawingControlPosition);
1532
            $shapeOptions = '';
1533
            if (count($this->drawingModes)) {
1534
                $this->output_js_contents .= ',
1535
					drawingModes: [';
1536
                $i = 0;
1537
                foreach ($this->drawingModes as $drawingMode) {
1538
                    if ($i > 0) {
1539
                        $this->output_js_contents .= ',';
1540
                    }
1541
                    $this->output_js_contents .= 'google.maps.drawing.OverlayType.'.strtoupper($drawingMode);
1542
                    if (strtoupper($drawingMode) != "MARKER") {
1543
                        $shapeOptions .= ',
1544
						'.strtolower($drawingMode).'Options: {
1545
							editable: true
1546
						}';
1547
                    }
1548
                    $i++;
1549
                }
1550
                $this->output_js_contents .= ']';
1551
            }
1552
            $this->output_js_contents .= '
1553
				}'.$shapeOptions.'
1554
			});
1555
			drawingManager.setMap('.$this->map_name.');
1556
			';
1557
1558
            $this->output_js_contents .= '
1559
			google.maps.event.addListener(drawingManager, "overlaycomplete", function(event) {
1560
				var newShape = event.overlay;
1561
				newShape.type = event.type;
1562
				';
1563
            if (count($this->drawingOnComplete)) {
1564
                foreach ($this->drawingOnComplete as $shape => $js) {
1565
                    $this->output_js_contents .= 'if (event.type==google.maps.drawing.OverlayType.'.strtoupper($shape).') {
1566
						'.$js.'
1567
					}
1568
					';
1569
                }
1570
            }
1571
1572
            if (count($this->drawingOnEdit)) {
1573 View Code Duplication
                if (isset($this->drawingOnEdit['polygon'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1574
                    $this->output_js_contents .= '
1575
				if (newShape.type==google.maps.drawing.OverlayType.POLYGON) {
1576
					var newShapePaths = newShape.getPaths();
1577
					for (var i=0; i<newShapePaths.length; i++) {
1578
						google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) {
1579
							'.$this->drawingOnEdit['polygon'].'
1580
						});
1581
						google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) {
1582
							'.$this->drawingOnEdit['polygon'].'
1583
						});
1584
						google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) {
1585
							'.$this->drawingOnEdit['polygon'].'
1586
						});
1587
					}
1588
				}';
1589
                }
1590 View Code Duplication
                if (isset($this->drawingOnEdit['polyline'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1591
                    $this->output_js_contents .= '
1592
				if (newShape.type==google.maps.drawing.OverlayType.POLYLINE) {
1593
					var newShapePaths = newShape.getPaths();
1594
					for (var i=0; i<newShapePaths.length; i++) {
1595
						google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) {
1596
							'.$this->drawingOnEdit['polyline'].'
1597
						});
1598
						google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) {
1599
							'.$this->drawingOnEdit['polyline'].'
1600
						});
1601
						google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) {
1602
							'.$this->drawingOnEdit['polyline'].'
1603
						});
1604
					}
1605
				}';
1606
                }
1607
                if (isset($this->drawingOnEdit['rectangle'])) {
1608
                    $this->output_js_contents .= '
1609
				if (newShape.type==google.maps.drawing.OverlayType.RECTANGLE) {
1610
					google.maps.event.addListener(newShape, "bounds_changed", function(event) {
1611
						'.$this->drawingOnEdit['rectangle'].'
1612
					});
1613
				}';
1614
                }
1615
                if (isset($this->drawingOnEdit['circle'])) {
1616
                    $this->output_js_contents .= '
1617
				if (newShape.type==google.maps.drawing.OverlayType.CIRCLE) {
1618
					google.maps.event.addListener(newShape, "radius_changed", function(event) {
1619
						'.$this->drawingOnEdit['circle'].'
1620
					});
1621
					google.maps.event.addListener(newShape, "center_changed", function(event) {
1622
						'.$this->drawingOnEdit['circle'].'
1623
					});
1624
				}';
1625
                }
1626
            }
1627
1628
            $this->output_js_contents .= '
1629
			});';
1630
        }
1631
1632
        if ($this->places) {
1633
            $placesLocationSet = false;
1634
1635
            if ($this->placesLocationSW != "" && $this->placesLocationNE != "") { // if search based on bounds
1636
1637
                $placesLocationSet = true;
1638
1639 View Code Duplication
                if ($this->is_lat_long($this->placesLocationSW)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1640
                    $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$this->placesLocationSW.');
1641
			';
1642
                } else {  // if centering the map on an address
1643
                    $lat_long = $this->get_lat_long_from_address($this->placesLocationSW);
1644
                    $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');
1645
			';
1646
                }
1647
1648 View Code Duplication
                if ($this->is_lat_long($this->placesLocationNE)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1649
                    $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$this->placesLocationNE.');
1650
			';
1651
                } else {  // if centering the map on an address
1652
                    $lat_long = $this->get_lat_long_from_address($this->placesLocationNE);
1653
                    $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');
1654
			';
1655
                }
1656
            }
1657
1658
            if (($placesLocationSet || $this->placesLocation != "") || count($this->placesTypes) || $this->placesName != "") {
1659
                $this->output_js_contents .= 'var placesRequest = {
1660
					';
1661
                if ($placesLocationSet) {
1662
                    $this->output_js_contents .= 'bounds: new google.maps.LatLngBounds(placesLocationSW, placesLocationNE)
1663
						';
1664
                } else {
1665
                    if ($this->placesLocation != "") { // if search based on a center point
1666 View Code Duplication
                        if ($this->is_lat_long($this->placesLocation)) { // if centering the map on a lat/long
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1667
                            $this->output_js_contents .= 'location: new google.maps.LatLng('.$this->placesLocation.')
1668
						';
1669
                        } else {  // if centering the map on an address
1670
                            $lat_long = $this->get_lat_long_from_address($this->placesLocation);
1671
                            $this->output_js_contents .= 'location: new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1672
						';
1673
                        }
1674
                        $this->output_js_contents .= ',radius: '.$this->placesRadius.'
1675
						';
1676
                    }
1677
                }
1678
1679
                if (count($this->placesTypes)) {
1680
                    $this->output_js_contents .= ',types: [\''.implode("','", $this->placesTypes).'\']
1681
						';
1682
                }
1683
                if ($this->placesName != "") {
1684
                    $this->output_js_contents .= ',name : \''.$this->placesName.'\'
1685
						';
1686
                }
1687
                $this->output_js_contents .= '};
1688
1689
				placesService = new google.maps.places.PlacesService('.$this->map_name.');
1690
				placesService.search(placesRequest, placesCallback);
1691
				';
1692
            }
1693
1694
            if ($this->placesAutocompleteInputID != "") {
1695
                $this->output_js_contents .= 'var autocompleteOptions = {
1696
					';
1697
                $autocompleteOptions = '';
1698
                if ($this->placesAutocompleteBoundSW != "" && $this->placesAutocompleteBoundNE != "") {
1699 View Code Duplication
                    if ($this->is_lat_long($this->placesAutocompleteBoundSW)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1700
                        $autocompleteOptionsSW = 'new google.maps.LatLng('.$this->placesAutocompleteBoundSW.')
1701
					';
1702
                    } else {  // if centering the map on an address
1703
                        $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundSW);
1704
                        $autocompleteOptionsSW = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1705
					';
1706
                    }
1707
1708 View Code Duplication
                    if ($this->is_lat_long($this->placesAutocompleteBoundNE)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1709
                        $autocompleteOptionsNE = 'new google.maps.LatLng('.$this->placesAutocompleteBoundNE.')
1710
					';
1711
                    } else {  // if centering the map on an address
1712
                        $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundNE);
1713
                        $autocompleteOptionsNE = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1714
					';
1715
                    }
1716
                    $autocompleteOptions .= 'bounds: new google.maps.LatLngBounds('.$autocompleteOptionsSW.', '.$autocompleteOptionsNE.')';
1717
                }
1718
                if (count($this->placesAutocompleteTypes)) {
1719
                    if ($autocompleteOptions != "") {
1720
                        $autocompleteOptions .= ',
1721
						 ';
1722
                    }
1723
                    $autocompleteOptions .= 'types: [\''.implode("','", $this->placesAutocompleteTypes).'\']';
1724
                }
1725
                $this->output_js_contents .= $autocompleteOptions;
1726
                $this->output_js_contents .= '}';
1727
1728
                $this->output_js_contents .= '
1729
				var autocompleteInput = document.getElementById(\''.$this->placesAutocompleteInputID.'\');
1730
1731
				placesAutocomplete = new google.maps.places.Autocomplete(autocompleteInput, autocompleteOptions);
1732
				';
1733
1734
                if ($this->placesAutocompleteBoundsMap) {
1735
                    $this->output_js_contents .= 'placesAutocomplete.bindTo(\'bounds\', map);
1736
					';
1737
                }
1738
1739
                if ($this->placesAutocompleteOnChange != "") {
1740
                    $this->output_js_contents .= 'google.maps.event.addListener(placesAutocomplete, \'place_changed\', function() {
1741
						'.$this->placesAutocompleteOnChange.'
1742
					});
1743
					';
1744
                }
1745
            }
1746
        }
1747
1748
        if ($this->onboundschanged != "") {
1749
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "bounds_changed", function(event) {
1750
    			'.$this->onboundschanged.'
1751
  			});
1752
			';
1753
        }
1754
        if ($this->oncenterchanged != "") {
1755
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "center_changed", function(event) {
1756
    			'.$this->oncenterchanged.'
1757
  			});
1758
			';
1759
        }
1760
        if ($this->onclick != "") {
1761
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "click", function(event) {
1762
    			'.$this->onclick.'
1763
  			});
1764
			';
1765
        }
1766
        if ($this->ondblclick != "") {
1767
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dblclick", function(event) {
1768
    			'.$this->ondblclick.'
1769
  			});
1770
			';
1771
        }
1772
        if ($this->ondrag != "") {
1773
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "drag", function(event) {
1774
    			'.$this->ondrag.'
1775
  			});
1776
			';
1777
        }
1778
        if ($this->ondragend != "") {
1779
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dragend", function(event) {
1780
    			'.$this->ondragend.'
1781
  			});
1782
			';
1783
        }
1784
        if ($this->ondragstart != "") {
1785
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dragstart", function(event) {
1786
    			'.$this->ondragstart.'
1787
  			});
1788
			';
1789
        }
1790
        if ($this->onidle != "") {
1791
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "idle", function(event) {
1792
    			'.$this->onidle.'
1793
  			});
1794
			';
1795
        }
1796
        if ($this->onmousemove != "") {
1797
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mousemove", function(event) {
1798
    			'.$this->onmousemove.'
1799
  			});
1800
			';
1801
        }
1802
        if ($this->onmouseout != "") {
1803
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mouseout", function(event) {
1804
    			'.$this->onmouseout.'
1805
  			});
1806
			';
1807
        }
1808
        if ($this->onmouseover != "") {
1809
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mouseover", function(event) {
1810
    			'.$this->onmouseover.'
1811
  			});
1812
			';
1813
        }
1814
        if ($this->onresize != "") {
1815
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "resize", function(event) {
1816
    			'.$this->onresize.'
1817
  			});
1818
			';
1819
        }
1820
        if ($this->onrightclick != "") {
1821
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "rightclick", function(event) {
1822
    			'.$this->onrightclick.'
1823
  			});
1824
			';
1825
        }
1826
        if ($this->ontilesloaded != "") {
1827
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "tilesloaded", function(event) {
1828
    			'.$this->ontilesloaded.'
1829
  			});
1830
			';
1831
        }
1832
        if ($this->onzoomchanged != "") {
1833
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "zoom_changed", function(event) {
1834
    			'.$this->onzoomchanged.'
1835
  			});
1836
			';
1837
        }
1838
1839
        // add markers
1840
        if (count($this->markers)) {
1841
            foreach ($this->markers as $marker) {
1842
                $this->output_js_contents .= $marker;
1843
            }
1844
        }
1845
        //
1846
1847
        if ($this->cluster) {
1848
            $this->output_js_contents .= '
1849
			var clusterOptions = {
1850
				gridSize: '.$this->clusterGridSize;
1851
            if ($this->clusterMaxZoom != "") {
1852
                $this->output_js_contents .= ',
1853
				maxZoom: '.$this->clusterMaxZoom;
1854
            }
1855
            if (!$this->clusterZoomOnClick) {
1856
                $this->output_js_contents .= ',
1857
				zoomOnClick: false';
1858
            }
1859
            if ($this->clusterAverageCenter) {
1860
                $this->output_js_contents .= ',
1861
				averageCenter: true';
1862
            }
1863
            if (count($this->clusterStyles) > 0) {
1864
1865
                $this->output_js_contents .= ',
1866
				styles: [ ';
1867
                $styleOutput = [];
1868
                foreach($this->clusterStyles as $clusterStyle){
1869
                    $attributes =[];
1870
                    foreach($clusterStyle as $key => $style){
1871
                        $attributes[] = $key.':"'.$style.'"';
1872
                    }
1873
                    $styleOutput[] = '{'.implode(',',$attributes).'}';
1874
                }
1875
                $this->output_js_contents .= implode(',',$styleOutput);
1876
                $this->output_js_contents .= ']';
1877
            }
1878
1879
            $this->output_js_contents .= ',
1880
				minimumClusterSize: '.$this->clusterMinimumClusterSize.'
1881
			};
1882
			markerCluster = new MarkerClusterer('.$this->map_name.', markers_'.$this->map_name.', clusterOptions);
1883
			';
1884
        }
1885
1886
        // add polylines
1887
        if (count($this->polylines)) {
1888
            foreach ($this->polylines as $polyline) {
1889
                $this->output_js_contents .= $polyline;
1890
            }
1891
        }
1892
        //
1893
1894
        // add polygons
1895
        if (count($this->polygons)) {
1896
            foreach ($this->polygons as $polygon) {
1897
                $this->output_js_contents .= $polygon;
1898
            }
1899
        }
1900
        //
1901
1902
        // add circles
1903
        if (count($this->circles)) {
1904
            foreach ($this->circles as $circle) {
1905
                $this->output_js_contents .= $circle;
1906
            }
1907
        }
1908
        //
1909
1910
        // add rectangles
1911
        if (count($this->rectangles)) {
1912
            foreach ($this->rectangles as $rectangle) {
1913
                $this->output_js_contents .= $rectangle;
1914
            }
1915
        }
1916
        //
1917
1918
        // add ground overlays
1919
        if (count($this->overlays)) {
1920
            foreach ($this->overlays as $overlay) {
1921
                $this->output_js_contents .= $overlay;
1922
            }
1923
        }
1924
        //
1925
1926
        if ($this->zoom == "auto") {
1927
            $this->output_js_contents .= '
1928
			fitMapToBounds_'.$this->map_name.'();
1929
			';
1930
        }
1931
1932
        if ($this->adsense) {
1933
            $this->output_js_contents .= '
1934
			var adUnitDiv = document.createElement("div");
1935
1936
		    // Note: replace the publisher ID noted here with your own
1937
		    // publisher ID.
1938
		    var adUnitOptions = {
1939
		    	format: google.maps.adsense.AdFormat.'.$this->adsenseFormat.',
1940
		    	position: google.maps.ControlPosition.'.$this->adsensePosition.',
1941
		    	publisherId: "'.$this->adsensePublisherID.'",
1942
		    	';
1943
            if ($this->adsenseChannelNumber != "") {
1944
                $this->output_js_contents .= 'channelNumber: "'.$this->adsenseChannelNumber.'",
1945
		    	';
1946
            }
1947
            $this->output_js_contents .= 'map: '.$this->map_name.',
1948
		    	visible: true
1949
		    };
1950
		    adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
1951
		    ';
1952
        }
1953
1954
        if ($this->directions && $this->directionsStart != "" && $this->directionsEnd != "") {
1955
            if ($this->directionsStart == "auto" && $this->directionsEnd == "auto") {
1956
                // Both start and finish are at the users current location
1957
                $this->output_js_contents .= '
1958
				// Try W3C Geolocation (Preferred)
1959
				if(navigator.geolocation) {
1960
					navigator.geolocation.getCurrentPosition(function(position) {
1961
						start = position.coords.latitude+","+position.coords.longitude;
1962
						calcRoute(start, start);
1963
					}, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1964
				// Browser doesn\'t support Geolocation
1965
				}else{
1966
					alert(\'Your browser does not support geolocation.\');
1967
				}
1968
				';
1969
            } elseif ($this->directionsStart == "auto") {
1970
                // The start point should be at the users current location
1971
                $this->output_js_contents .= '
1972
				// Try W3C Geolocation (Preferred)
1973
				if(navigator.geolocation) {
1974
					navigator.geolocation.getCurrentPosition(function(position) {
1975
						start = position.coords.latitude+","+position.coords.longitude;
1976
						calcRoute(start, \''.$this->directionsEnd.'\');
1977
					}, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1978
				// Browser doesn\'t support Geolocation
1979
				}else{
1980
					alert(\'Your browser does not support geolocation.\');
1981
				}
1982
				';
1983
            } elseif ($this->directionsEnd == "auto") {
1984
                // The end point should be at the users current location
1985
                $this->output_js_contents .= '
1986
				// Try W3C Geolocation (Preferred)
1987
				if(navigator.geolocation) {
1988
					navigator.geolocation.getCurrentPosition(function(position) {
1989
						end = position.coords.latitude+","+position.coords.longitude;
1990
						calcRoute(\''.$this->directionsStart.'\', end);
1991
					}, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1992
				// Browser doesn\'t support Geolocation
1993
				}else{
1994
					alert(\'Your browser does not support geolocation.\');
1995
				}
1996
				';
1997
            } else {
1998
                // The start and end point are at pre-defined locations
1999
                $this->output_js_contents .= '
2000
				calcRoute(\''.$this->directionsStart.'\', \''.$this->directionsEnd.'\');
2001
				';
2002
            }
2003
        }
2004
2005
        if ($this->onload != "") {
2006
            $this->output_js_contents .= '
2007
				'.$this->onload;
2008
        }
2009
2010
        $this->output_js_contents .= '
2011
2012
			}
2013
2014
		';
2015
2016
        // add markers
2017
        $this->output_js_contents .= '
2018
		function createMarker_'.$this->map_name.'(markerOptions) {
2019
			var marker = new google.maps.Marker(markerOptions);
2020
			markers_'.$this->map_name.'.push(marker);
2021
			lat_longs_'.$this->map_name.'.push(marker.getPosition());
2022
			return marker;
2023
		}
2024
		';
2025
        //
2026
2027
        if ($this->directions) {
2028
            $this->output_js_contents .= 'function calcRoute(start, end) {
2029
2030
			var request = {
2031
			    	origin:start,
2032
			    	destination:end,
2033
			    	travelMode: google.maps.TravelMode.'.$this->directionsMode.'
2034
			    	';
2035
2036
            if (count($this->directionsWaypointArray)) {
2037
                $directionsWaypointStr = '';
2038
                foreach ($this->directionsWaypointArray as $waypoint) {
2039
                    if ($directionsWaypointStr != '') {
2040
                        $directionsWaypointStr .= ',';
2041
                    }
2042
                    $directionsWaypointStr .= '{ location: "'.$waypoint.'", stopover: true}';
2043
                }
2044
                $this->output_js_contents .= ', waypoints: ['.$directionsWaypointStr.']';
2045
2046
                if ($this->directionsWaypointsOptimize) {
2047
                    $this->output_js_contents .= ', optimizeWaypoints: true';
2048
                }
2049
            }
2050
            if ($this->region != "" && strlen($this->region) == 2) {
2051
                $this->output_js_contents .= ',region: '.strtoupper($this->region).'
2052
					';
2053
            }
2054
            if (trim($this->directionsUnits) != "" && (strtolower(trim($this->directionsUnits)) == "metric" || strtolower(trim($this->directionsUnits)) == "imperial")) {
2055
                $this->output_js_contents .= ',unitSystem: google.maps.UnitSystem.'.strtoupper(trim($this->directionsUnits)).'
2056
					';
2057
            }
2058
            if ($this->directionsAvoidTolls) {
2059
                $this->output_js_contents .= ',avoidTolls: true
2060
					';
2061
            }
2062
            if ($this->directionsAvoidHighways) {
2063
                $this->output_js_contents .= ',avoidHighways: true
2064
					';
2065
            }
2066
2067
            $this->output_js_contents .= '
2068
			};
2069
			  	directionsService.route(request, function(response, status) {
2070
			    	if (status == google.maps.DirectionsStatus.OK) {
2071
			      		directionsDisplay.setDirections(response);
2072
			    	}else{
2073
			    		switch (status) {
2074
			    			case "NOT_FOUND": { alert("Either the start location or destination were not recognised"); break }
2075
			    			case "ZERO_RESULTS": { alert("No route could be found between the start location and destination"); break }
2076
			    			case "MAX_WAYPOINTS_EXCEEDED": { alert("Maximum waypoints exceeded. Maximum of 8 allowed"); break }
2077
			    			case "INVALID_REQUEST": { alert("Invalid request made for obtaining directions"); break }
2078
			    			case "OVER_QUERY_LIMIT": { alert("This webpage has sent too many requests recently. Please try again later"); break }
2079
			    			case "REQUEST_DENIED": { alert("This webpage is not allowed to request directions"); break }
2080
			    			case "UNKNOWN_ERROR": { alert("Unknown error with the server. Please try again later"); break }
2081
			    		}
2082
			    	}
2083
			  	});
2084
			}
2085
			';
2086
        }
2087
2088
        if ($this->places) {
2089
            $this->output_js_contents .= 'function placesCallback(results, status) {
2090
				if (status == google.maps.places.PlacesServiceStatus.OK) {
2091
					for (var i = 0; i < results.length; i++) {
2092
2093
						var place = results[i];
2094
2095
						var placeLoc = place.geometry.location;
2096
						var placePosition = new google.maps.LatLng(placeLoc.lat(), placeLoc.lng());
2097
						var markerOptions = {
2098
				 			map: '.$this->map_name.',
2099
				        	position: placePosition
2100
				      	};
2101
				      	var marker = createMarker_'.$this->map_name.'(markerOptions);
2102
				      	marker.set("content", place.name);
2103
				      	google.maps.event.addListener(marker, "click", function() {
2104
				        	iw_'.$this->map_name.'.setContent(this.get("content"));
2105
				        	iw_'.$this->map_name.'.open('.$this->map_name.', this);
2106
				      	});
2107
2108
				      	lat_longs_'.$this->map_name.'.push(placePosition);
2109
2110
					}
2111
					';
2112
            if ($this->zoom == "auto") {
2113
                $this->output_js_contents .= 'fitMapToBounds_'.$this->map_name.'();';
2114
            }
2115
            $this->output_js_contents .= '
2116
				}
2117
			}
2118
			';
2119
        }
2120
2121 View Code Duplication
        if ($this->zoom == "auto") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2122
            $this->output_js_contents .= '
2123
			function fitMapToBounds_'.$this->map_name.'() {
2124
				var bounds = new google.maps.LatLngBounds();
2125
				if (lat_longs_'.$this->map_name.'.length>0) {
2126
					for (var i=0; i<lat_longs_'.$this->map_name.'.length; i++) {
2127
						bounds.extend(lat_longs_'.$this->map_name.'[i]);
2128
					}
2129
					'.$this->map_name.'.fitBounds(bounds);
2130
				}
2131
			}
2132
			';
2133
        }
2134
2135 View Code Duplication
        if ($this->loadAsynchronously) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2136
            $this->output_js_contents .= '
2137
			function loadScript_'.$this->map_name.'() {
2138
				var script = document.createElement("script");
2139
  				script.type = "text/javascript";
2140
  				script.src = "'.$apiLocation.'&callback=initialize_'.$this->map_name.'";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $apiLocation does not seem to be defined for all execution paths leading up to this point.
Loading history...
2141
  				document.body.appendChild(script);
2142
			}
2143
			window.onload = loadScript_'.$this->map_name.';
2144
			';
2145
        } else {
2146
            $this->output_js_contents .= '
2147
			google.maps.event.addDomListener(window, "load", initialize_'.$this->map_name.');
2148
			';
2149
        }
2150
2151
        // Minify the Javascript if the $minifyJS config value is true. Requires Jsmin.php and PHP 5+
2152
        if ($this->minifyJS) {
2153
            $CI = \App::make('jsmin');
2154
            $this->output_js_contents = $CI->jsmin->min($this->output_js_contents);
2155
        }
2156
2157
        if ($this->jsfile == "") {
2158
            $this->output_js .= $this->output_js_contents;
2159
        } else { // if needs writing to external js file
2160
            if (!$handle = fopen($this->jsfile, "w")) {
2161
                $this->output_js .= $this->output_js_contents;
2162
            } else {
2163
                if (!fwrite($handle, $this->output_js_contents)) {
2164
                    $this->output_js .= $this->output_js_contents;
2165
                } else {
2166
                    $this->output_js .= '
2167
					<script src="'.$this->jsfile.'" type="text/javascript"></script>';
2168
                }
2169
            }
2170
        }
2171
2172
        if ($this->jsfile == "") {
2173
            $this->output_js .= '
2174
			//]]>
2175
			</script>';
2176
        }
2177
2178
        // set height and width
2179
        if (is_numeric($this->map_width)) { // if no width type set
2180
            $this->map_width = $this->map_width.'px';
2181
        }
2182
        if (is_numeric($this->map_height)) { // if no height type set
2183
            $this->map_height = $this->map_height.'px';
2184
        }
2185
        //
2186
2187
        $this->output_html .= '<div id="'.$this->map_div_id.'" style="width:'.$this->map_width.'; height:'.$this->map_height.';"'.(($this->class != "") ? ' class="'.$this->class.'"' : '').'></div>';
2188
2189
        ++$this->maps_loaded;
2190
2191
        return array('js' => $this->output_js, 'html' => $this->output_html, 'markers' => $this->markersInfo);
2192
    }
2193
2194
    public function is_lat_long($input)
2195
    {
2196
        $input = str_replace(", ", ",", trim($input));
2197
        $input = explode(",", $input);
2198
        if (count($input) == 2) {
2199
            if (is_numeric($input[0]) && is_numeric($input[1])) { // is a lat long
2200
                return true;
2201
            } else { // not a lat long - incorrect values
2202
                return false;
2203
            }
2204
        } else { // not a lat long - too many parts
2205
            return false;
2206
        }
2207
    }
2208
2209
    public function get_lat_long_from_address($address, $attempts = 0)
2210
    {
2211
        $lat = 0;
2212
        $lng = 0;
2213
2214
        $error = '';
2215
2216
        if ($this->geocodeCaching) { // if caching of geocode requests is activated
2217
2218
            $CI = & get_instance();
0 ignored issues
show
Bug introduced by
The function get_instance was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2218
            $CI = & /** @scrutinizer ignore-call */ get_instance();
Loading history...
2219
            $CI->load->database();
2220
            $CI->db->select("latitude,longitude");
2221
            $CI->db->from("geocoding");
2222
            $CI->db->where("address", trim(strtolower($address)));
2223
            $query = $CI->db->get();
2224
2225
            if ($query->num_rows() > 0) {
2226
                $row = $query->row();
2227
2228
                return array($row->latitude, $row->longitude);
2229
            }
2230
        }
2231
	//utf8_encode($address) will return only english adress mean it's take only english address.
2232
    	// Remove utf8_encode from urlencode then it'll support all languages(eg. en, ur, chinese, russian, japanese, greek etc.)
2233
        // $data_location = "https://maps.google.com/maps/api/geocode/json?address=".urlencode(utf8_encode($address)); //Old One just for english
2234
	    $data_location = "https://maps.google.com/maps/api/geocode/json?address=".urlencode($address); // New One for every language.
2235
        if ($this->region != "" && strlen($this->region) == 2) {
2236
            $data_location .= "&region=".$this->region;
2237
        }
2238
        $data = file_get_contents($data_location);
2239
2240
        $data = json_decode($data);
2241
2242
        if ($data->status == "OK") {
2243
            $lat = $data->results[0]->geometry->location->lat;
2244
            $lng = $data->results[0]->geometry->location->lng;
2245
2246
            if ($this->geocodeCaching) { // if we to need to cache this result
2247
                if ($address != "" && $lat != 0 && $lng != 0) {
2248
                    $data = array(
2249
                        "address" => trim(strtolower($address)),
2250
                        "latitude" => $lat,
2251
                        "longitude" => $lng,
2252
                    );
2253
                    $CI->db->insert("geocoding", $data);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $CI does not seem to be defined for all execution paths leading up to this point.
Loading history...
2254
                }
2255
            }
2256
        } else {
2257
            if ($data->status == "OVER_QUERY_LIMIT") {
2258
                $error = $data->status;
2259
                if ($attempts < 2) {
2260
                    sleep(1);
2261
                    ++$attempts;
2262
                    list($lat, $lng, $error) = $this->get_lat_long_from_address($address, $attempts);
2263
                }
2264
            }
2265
        }
2266
2267
        return array($lat, $lng, $error);
2268
    }
2269
}
2270