Mercurial > public > geoquiz
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GeoQuiz/Controllers/MapController.swift Thu Nov 10 10:27:28 2022 +0100 @@ -0,0 +1,36 @@ +// +// MapController.swift +// GeoQuiz +// +// Created by Dennis Concepción Martín on 22/10/22. +// + +import Foundation +import MapKit + +class MapController: ObservableObject { + @Published var image: UIImage? = nil + + func getMapImage(lat: Double, lon: Double) { + let region = MKCoordinateRegion( + center: CLLocationCoordinate2D(latitude: lat, longitude: lon), + span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05) + ) + + // Map options + let mapOptions = MKMapSnapshotter.Options() + mapOptions.region = region + mapOptions.size = CGSize(width: 500, height: 500) + mapOptions.pointOfInterestFilter = .excludingAll + + // Create the snapshotter and run it + let snapshotter = MKMapSnapshotter(options: mapOptions) + snapshotter.start { (snapshot, error) in + if let snapshot = snapshot { + self.image = snapshot.image + } else if let error = error { + print(error.localizedDescription) + } + } + } +}