skip to Main Content

I am using MapKit for the first time and I am trying to use it but currently even a basic map is not working, I have done a lot of tutorials etc but even this basic version doesn’t seem to be working. I am using Swift, SwiftUI and XCode 14

The following code is what I am using

import SwiftUI
import MapKit

struct MapView : View {
    @State private var region = MKCoordinateRegion(
        center: CLLocationCoordinate2D(latitude: 25.7617, longitude: 80.1918),
        span: MKCoordinateSpan(latitudeDelta: 10, longitudeDelta: 10)
    )
    
    var body: some View {
        Map(coordinateRegion: $region)
    }
}

I’ve also tried embedding it in a VStack etc but it still doesn’t display a map at all

I am just trying to display a basic map which I eventually can add markers etc

2

Answers


  1. Your question is a bit unclear, did you put your mapview in a preview builder ? I just copy and paste your code and I didn’t encounter problems.

    struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        MapView()
    }}
    
    Login or Signup to reply.
  2. It’s possible that you haven’t added the capability to your app. If you don’t do that, MapKit will not function. Review the documentation here can help with that.

    https://developer.apple.com/documentation/xcode/configuring-maps-support

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search