-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeolocate OSM
More file actions
83 lines (70 loc) · 2.72 KB
/
geolocate OSM
File metadata and controls
83 lines (70 loc) · 2.72 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
import UIKit
import CoreLocation
import MapKit
class LitterReportViewController: UIViewController {
// MARK: - Properties
private let imagePickerController = UIImagePickerController()
private var selectedImage: UIImage?
private var locationManager: CLLocationManager?
private var currentLocation: CLLocation?
// MARK: - Outlets
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var takePhotoButton: UIButton!
@IBOutlet weak var submitButton: UIButton!
// MARK: - Actions
@IBAction func takePhotoButtonTapped(_ sender: Any) {
showImagePicker()
}
@IBAction func submitButtonTapped(_ sender: Any) {
guard let location = currentLocation else {
showMissingLocationAlert()
return
}
guard let image = selectedImage else {
showMissingImageAlert()
return
}
submitLitterReport(location: location, image: image)
}
// MARK: - Private
private func showImagePicker() {
imagePickerController.sourceType = .camera
imagePickerController.delegate = self
present(imagePickerController, animated: true)
}
private func showMissingLocationAlert() {
let alertController = UIAlertController(title: "Missing Location",
message: "Unable to determine current location. Please try again.",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default)
alertController.addAction(okAction)
present(alertController, animated: true)
}
private func showMissingImageAlert() {
let alertController = UIAlertController(title: "Missing Image",
message: "Please take a photo of the litter.",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default)
alertController.addAction(okAction)
present(alertController, animated: true)
}
private func submitLitterReport(location: CLLocation, image: UIImage) {
// TODO: Implement code to submit litter report
// 1. Upload the image and location data to a server
// 2. Add a pin to the map at the specified location
}
private func setupLocationManager() {
locationManager = CLLocationManager()
locationManager?.desiredAccuracy = kCLLocationAccuracyBest
locationManager?.distanceFilter = kCLDistanceFilterNone
locationManager?.delegate = self
}
private func requestLocationPermission() {
let status = CLLocationManager.authorizationStatus()
switch status {
case .authorizedWhenInUse, .authorizedAlways:
// TODO: Start updating location
break
case .notDetermined:
locationManager?.requestWhenInUseAuthorization()
case .restricted, .denied