-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathios-swift-core-location.html
More file actions
151 lines (132 loc) · 5.16 KB
/
ios-swift-core-location.html
File metadata and controls
151 lines (132 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>TopDownU Tutorials</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/2-col-portfolio.css" rel="stylesheet">
<link href="tutorials.css" rel="stylesheet">
</head>
<body>
<div class="header">
<h2 class="tutorialTitle">Getting User's Location</h2>
<p class="tutorialDescription">in 5 simple steps</p>
<p class="moreTutorials"><a class="moreTutorialsLink" href="http://topdownu.com/tutorials">MORE TUTORIALS</a></p>
</div>
<div class="row">
<div class="row-white">
<div class="padding-box">
<h2 class="stepTitle">Pre-Requisites</h2>
<p class="stepParagraph"></p>
</div>
</div>
</div>
<div class="row">
<div class="row-gray">
<div class="padding-box">
<h2 class="stepTitle">Import CoreLocation framework</h2>
<p class="stepParagraph"></p>
</div>
<div class="codeSnippet">
<p class="code">
import CoreLocation
</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 1 of 5</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-white">
<div class="padding-box">
<h2 class="stepTitle">Inherit delegate class</h2>
<p class="stepParagraph"></p>
</div>
<div class="codeSnippet">
<p class="code">
class ViewController: UIViewController, CLLocationManagerDelegate {
</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 2 of 5</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-gray">
<div class="padding-box">
<h2 class="stepTitle">Initialize location manager</h2>
<p class="stepParagraph"></p>
</div>
<div class="codeSnippet">
<p class="code">
var locationManager : CLLocationManager!<br/><br/>
override func viewDidLoad() {<br/>
super.viewDidLoad()<br/>
// Do any additional setup after loading the view, typically from a nib.<br/><br/>
locationManager = CLLocationManager()<br/>
locationManager.delegate = self<br/>
locationManager.desiredAccuracy = kCLLocationAccuracyBest<br/>
locationManager.requestAlwaysAuthorization()<br/><br/>
if(CLLocationManager.locationServicesEnabled()){<br/>
locationManager.startUpdatingLocation()<br/>
}<br/>
}<br/>
</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 3 of 5</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-white">
<div class="padding-box">
<h2 class="stepTitle">Implement delegate methods</h2>
<p class="stepParagraph"></p>
</div>
<div class="codeSnippet">
<p class="code">
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){<br/>
let userLocation:CLLocation = locations[0] as CLLocation<br/>
manager.stopUpdatingLocation()<br/>
print("Latitude: \(userLocation.coordinate.latitude)")<br/>
print("Longtitude: \(userLocation.coordinate.longitude)")<br/>
}<br/><br/>
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {<br/>
print(error)<br/>
}
</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 4 of 5</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-gray">
<div class="padding-box">
<h2 class="stepTitle">Run and test</h2>
<p class="stepParagraph"></p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 5 of 5</h6>
</div>
</div>
</div>
<!-- Footer -->
<footer class="py-5 bg-light">
<center>Copyright TopDownU 2017</center>
</footer>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/popper/popper.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>