Failed Conditions
Pull Request — master (#250)
by
unknown
05:48
created

pokestops.maps.js ➔ ... ➔ $.done   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 16
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
B pokestops.maps.js ➔ ... ➔ navigator.geolocation.getCurrentPosition 0 12 5
1
/** global: google */
2
function initMap()
3
{
4
5
	var locations;
6
7
	$.ajax({
8
		'async': true,
9
		'type': "GET",
10
		'global': false,
11
		'dataType': 'text',
12
		'url': "core/process/aru.php",
13
		'data': { 'request': "", 'target': 'arrange_url', 'method': 'method_target', 'type' : 'pokestop' },
14
		'success': function (data) {
15
			
16
		
17
			$.getJSON("core/json/variables.json", function (variables) {
18
				var latitude = Number(variables['system']['map_center_lat']);
19
				var longitude = Number(variables['system']['map_center_long']);
20
				var zoom_level = Number(variables['system']['zoom_level']);
21
22
		 
23
				// Convert return to JSON Array
24
			
25
				locations = JSON.parse(data);
26
				var arr = [];
27
			
28
				for (i = 0; i < locations.length; i++) {
29
					arr.push(JSON.parse(locations[i]));
30
				}
31
				
32
				var map = new google.maps.Map(document.getElementById('map'), {
33
					center: {
34
						lat: latitude,
35
						lng: longitude
36
					},
37
					zoom: zoom_level,
38
					zoomControl: true,
39
					scaleControl: false,
40
					scrollwheel: true,
41
					disableDoubleClickZoom: false,
42
					streetViewControl: false,
43
					mapTypeControlOptions: {
44
						mapTypeIds: [
45
							google.maps.MapTypeId.ROADMAP,
46
							'pogo_style',
47
							'dark_style',
48
						]
49
					}
50
				});
51
			
52
				$.getJSON( 'core/json/pogostyle.json', function( data ) {
53
					var styledMap_pogo = new google.maps.StyledMapType(data, {name: 'PoGo'});
54
					map.mapTypes.set('pogo_style', styledMap_pogo);
55
				});
56
				$.getJSON( 'core/json/darkstyle.json', function( data ) {
57
					var styledMap_dark = new google.maps.StyledMapType(data, {name: 'Dark'});
58
					map.mapTypes.set('dark_style', styledMap_dark);
59
				});
60
				$.getJSON( 'core/json/defaultstyle.json', function( data ) {
61
					map.set('styles', data);
62
				});
63
64
				$.ajax({
65
					'async': true,
66
					'type': "GET",
67
					'global': false,
68
					'dataType': 'json',
69
					'url': "core/process/aru.php",
70
					'data': {
71
						'request': "",
72
						'target': 'arrange_url',
73
						'method': 'method_target',
74
						'type': 'maps_localization_coordinates'
75
					}
76
				}).done(function(coordinates) {
77
					if (navigator.geolocation) {
0 ignored issues
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
78
						navigator.geolocation.getCurrentPosition(function(position) {
79
							var pos = {
80
								lat: position.coords.latitude,
81
								lng: position.coords.longitude
82
							};
83
84
							if (position.coords.latitude <= coordinates.max_latitude && position.coords.latitude >= coordinates.min_latitude) {
85
								if (position.coords.longitude <= coordinates.max_longitude && position.coords.longitude >= coordinates.min_longitude) {
86
									map.setCenter(pos);
87
								}
88
							}
89
						});
90
					}
91
				});
92
93
				var infowindow = new google.maps.InfoWindow();
94
			
95
				var marker, i;
96
		
97
				for (i = 0; i < arr.length; i++) {
98
					marker = new google.maps.Marker({
99
						position: new google.maps.LatLng(arr[i][2], arr[i][3]),
100
						map: map,
101
						icon: 'core/img/'+arr[i][1]
102
					});
103
		
104
					google.maps.event.addListener(marker, 'click', (function (marker, i) {
105
							return function () {
106
								infowindow.setContent(arr[i][0]);
107
								infowindow.open(map, marker);
108
							}
109
					})(marker, i));
110
				}
111
			
112
					
113
			});
114
		}
115
	});
116
}
117