mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-04-26 02:28:36 +02:00
Add examples project
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
See LICENSE folder for this sample’s licensing information.
|
||||
|
||||
Abstract:
|
||||
A view that hosts an `MKMapView`.
|
||||
*/
|
||||
|
||||
import SwiftUI
|
||||
import MapKit
|
||||
|
||||
struct MapView: UIViewRepresentable {
|
||||
var coordinate: CLLocationCoordinate2D
|
||||
|
||||
func makeUIView(context: Context) -> MKMapView {
|
||||
MKMapView(frame: .zero)
|
||||
}
|
||||
|
||||
func updateUIView(_ view: MKMapView, context: Context) {
|
||||
let span = MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)
|
||||
let region = MKCoordinateRegion(center: coordinate, span: span)
|
||||
view.setRegion(region, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct MapView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MapView(coordinate: landmarkData[0].locationCoordinate)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user