Passed
Pull Request — master (#250)
by Markus
16:08 queued 09:43
created

tor.geolocation.getCurrentPosition   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 12
rs 8.8571
1
/** global: google */
2
/** global: navigator */
3
4
function initMap()
5
{
6
	$.ajax({
7
		'async': true,
8
		'type': "GET",
9
		'global': false,
10
		'dataType': 'json',
11
		'url': "core/process/aru.php",
12
		'data': { 'request': "", 'target': 'arrange_url', 'method': 'method_target', 'type' : 'pokestop' },
13
		'success': function (pokestops) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
14
			
15
		
16
			$.getJSON("core/json/variables.json", function (variables) {
17
				var latitude = Number(variables['system']['map_center_lat']);
18
				var longitude = Number(variables['system']['map_center_long']);
19
				var zoom_level = Number(variables['system']['zoom_level']);
20
21
				var map = new google.maps.Map(document.getElementById('map'), {
22
					center: {
23
						lat: latitude,
24
						lng: longitude
25
					},
26
					zoom: zoom_level,
27
					zoomControl: true,
28
					scaleControl: false,
29
					scrollwheel: true,
30
					disableDoubleClickZoom: false,
31
					streetViewControl: false,
32
					mapTypeControlOptions: {
33
						mapTypeIds: [
34
							google.maps.MapTypeId.ROADMAP,
35
							'pogo_style',
36
							'dark_style',
37
						]
38
					}
39
				});
40
			
41
				$.getJSON( 'core/json/pogostyle.json', function( data ) {
42
					var styledMap_pogo = new google.maps.StyledMapType(data, {name: 'PoGo'});
43
					map.mapTypes.set('pogo_style', styledMap_pogo);
44
				});
45
				$.getJSON( 'core/json/darkstyle.json', function( data ) {
46
					var styledMap_dark = new google.maps.StyledMapType(data, {name: 'Dark'});
47
					map.mapTypes.set('dark_style', styledMap_dark);
48
				});
49
				$.getJSON( 'core/json/defaultstyle.json', function( data ) {
50
					map.set('styles', data);
51
				});
52
53
				$.ajax({
54
					'async': true,
55
					'type': "GET",
56
					'global': false,
57
					'dataType': 'json',
58
					'url': "core/process/aru.php",
59
					'data': {
60
						'request': "",
61
						'target': 'arrange_url',
62
						'method': 'method_target',
63
						'type': 'maps_localization_coordinates'
64
					}
65
				}).done(function(coordinates) {
66
					if (navigator.geolocation) {
67
						navigator.geolocation.getCurrentPosition(function(position) {
68
							var pos = {
69
								lat: position.coords.latitude,
70
								lng: position.coords.longitude
71
							};
72
73
							if (position.coords.latitude <= coordinates.max_latitude && position.coords.latitude >= coordinates.min_latitude) {
74
								if (position.coords.longitude <= coordinates.max_longitude && position.coords.longitude >= coordinates.min_longitude) {
75
									map.setCenter(pos);
76
								}
77
							}
78
						});
79
					}
80
				});
81
82
				var infowindow = new google.maps.InfoWindow();
83
			
84
				var marker, i;
85
		
86
				for (i = 0; i < pokestops.length; i++) {
87
					marker = new google.maps.Marker({
88
						position: new google.maps.LatLng(pokestops[i][2], pokestops[i][3]),
89
						map: map,
90
						icon: 'core/img/'+pokestops[i][1]
91
					});
92
		
93
					google.maps.event.addListener(marker, 'click', (function (marker, i) {
94
							return function () {
95
								infowindow.setContent(pokestops[i][0]);
96
								infowindow.open(map, marker);
97
							}
98
					})(marker, i));
99
				}
100
			
101
					
102
			});
103
		}
104
	});
105
}
106