Mercurial > public > geoquiz
comparison GeoQuiz/Controllers/MapController.swift @ 29:f5a2c2dab208
fix files structure
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 10 Nov 2022 10:27:28 +0100 |
parents | GeoQuiz/Models/Controllers/MapController.swift@425078c01194 |
children |
comparison
equal
deleted
inserted
replaced
28:f51b70c2cccc | 29:f5a2c2dab208 |
---|---|
1 // | |
2 // MapController.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 22/10/22. | |
6 // | |
7 | |
8 import Foundation | |
9 import MapKit | |
10 | |
11 class MapController: ObservableObject { | |
12 @Published var image: UIImage? = nil | |
13 | |
14 func getMapImage(lat: Double, lon: Double) { | |
15 let region = MKCoordinateRegion( | |
16 center: CLLocationCoordinate2D(latitude: lat, longitude: lon), | |
17 span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05) | |
18 ) | |
19 | |
20 // Map options | |
21 let mapOptions = MKMapSnapshotter.Options() | |
22 mapOptions.region = region | |
23 mapOptions.size = CGSize(width: 500, height: 500) | |
24 mapOptions.pointOfInterestFilter = .excludingAll | |
25 | |
26 // Create the snapshotter and run it | |
27 let snapshotter = MKMapSnapshotter(options: mapOptions) | |
28 snapshotter.start { (snapshot, error) in | |
29 if let snapshot = snapshot { | |
30 self.image = snapshot.image | |
31 } else if let error = error { | |
32 print(error.localizedDescription) | |
33 } | |
34 } | |
35 } | |
36 } |