'Creating mapmarker in Swiftui interface?
I've been trying to create a mapmarker on my screen via mapkit for 1 week. These mapmarkers come from the api I have as latitude and longitude. However, I learned swift 1 month ago and I'm having a hard time. Is there someone to help me? Code and screenshot attached.
Obviously what I want is to know where to write the codes and to know which codes to use. (My interface is swift, there is usually a storyboard interface on the internet)
import SwiftUI
import MapKit
struct depremHaritasi: View {
@State var quakes: [EarthQuake] = []
@State var coordinateRegion = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 38.9520281, longitude: 35.6980142),
span: MKCoordinateSpan(latitudeDelta: 30, longitudeDelta: 10))
var body: some View {
Map(coordinateRegion: $coordinateRegion)
.edgesIgnoringSafeArea(.all)
.onAppear {
Api().getEarthQuake { (quakes) in
self.quakes = quakes
}
}
}
}
struct depremHaritasi_Previews: PreviewProvider {
static var previews: some View {
depremHaritasi()
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
