TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Project 14 : Map view does not work on Simulator nor on real device, but it works in Xcode preview

Forums > 100 Days of SwiftUI

Hi there,

currently working on tutorial 4/12 of Bucket List project and I am stuck within the first step : showing the inital map with the location of London.

In the preview window of Xcode 14.2 I see the map as expected, but when I run the app in the simulator I only see "Loading ..." and the same is true when running it on a real device (both run iOS 16.2).

struct MapKitView: View {

    @State  private var mapRegion = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 51.5, longitude: -0.12), span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2))

    var body: some View {

        Map(coordinateRegion: $mapRegion)
    }
}

struct MapKitView_Previews: PreviewProvider {
    static var previews: some View {
        MapKitView()
    }
}

If it would happen only in the simulator I would assume it has someting to do with the date & time or the location / region settings (as found in some but maybe out-of-date answers on this topic with older MapKit APIs), but this does not make sense for the real iPhone.

I also started the Apple Map app on its on, so that all acknowledge dialogs are out of the way.

Are there new restrictions for using MapKit or the SwiftUI Map view that have to be fulfilled - Info.plist or something alike?

2      

I tries it in a new Xcode project, and found no errors! Display map as expected

2      

Hi @NigelGee,

thanks for testing it on your side!

The success on your side pushed me in the right direction, to see that I was "code blind": a stupid typo of mine was the cause of this issue - its really funny and strange, how our "code focused" minds sometimes turns around in "closed cycles", unable to break out of the cycle and reach out for the mighty obvious ;-)

Thanks for getting my out of there.

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.