Missing parameter error in the first couple of steps

Hello, I'm following along with this tutorial, and am getting this error on the first steps of the video: Missing argument for parameter 'mapRect' in call

Here is my code:

import SwiftUI
import MapKit

struct ContentView: View {
    var body: some View {
        Map()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Is the creator of the video somehow using a different version of the MapKit API than me? As far as I can tell, I am fully up-to-date. I'm on Ventura 13.4 using Xcode 14.3.1. I'm new to developing for Apple platforms, so maybe there's something obvious that I'm missing here?

Replies

You need either mapRect or mapRegion parameter.

Get details here: https://swiftwithmajid.com/2020/07/29/using-mapkit-with-swiftui/

The session video you're referring to is from WWDC23, so it is using the new APIs introduced. The Map struct with the initialiser you are trying to use is only available from iOS 17 and aligned releases. To use these new features you will have to update to Xcode 15.

In the meantime, use one of the old (marked as deprecated) initialisers that work in Xcode 14.3.1.

Understood, thank you both for the responses!

  • Can you please close this thread by marking an answer as correct so that others know your issue has been solved.

Add a Comment

Hi, I'm having a similar issue, the using MapKit the way it's done in the WWDC23 tutorial does not work (I'm using Xcode 14.3.1 also). I tried to solve my code using the answers above but using the deprecated initializers doesn't not work either.

After looking for hours on blogs and tutorial, it looks like the MapKit API got changed and possibly only working for iOS 17 using Xcode 15 Beta. But how on earth is anyone using MapKit to show a map for iOS 16 and previous versions now?

Here is my code below, along with the error messages I get:

import SwiftUI
import MapKit

struct MapView: View {
    @State private var userTrackingMode: MapUserTrackingMode = .follow
    @State private var region = MKCoordinateRegion(
            center: CLLocationCoordinate2D(
                latitude: 42.7878,
                longitude: -74.9323),
            span: MKCoordinateSpan(
                latitudeDelta: 0.1,
                longitudeDelta: 0.1))

    var body: some View {
        Map(coordinateRegion: $region,
            interactionModes: MapInteractionModes.all,
            showsUserLocation: true,
            userTrackingMode: $userTrackingMode)
    }
}

struct MapView_Previews: PreviewProvider {
    static var previews: some View {
        MapView()
    }
}

Errors related to the the use of 'Map()':

Extra arguments at positions #1, #2, #3, #4 in call
Static method 'buildExpression' requires that 'Map' conform to 'View'

Can someone help to find a way to use MapKit on iOS 16, looks like all resources online are outdated or referring to iOS 17. Thanks!