When 500m is specified in MKCoordinateRegion, it stops with an error.

I used Xcode 14 Beta 2.

It worked fine on Xcode 13.

If you set it to 3000m as shown below, it will work without problems.

Below is the sample code.

import SwiftUI
import MapKit

enum MapType {
  case standard
  case satellite
  case hybrid
  case satelliteFlyover
  case hybridFlyover
  case mutedStandard
}

struct MapView: UIViewRepresentable {
  let searchKey: String
   
  let mapType: MapType

  func makeUIView(context: Context) -> MKMapView {
    return MKMapView()
  }
   
  func updateUIView(_ uiView: MKMapView, context: Context) {

    switch mapType {
    case .standard:
      uiView.preferredConfiguration = MKStandardMapConfiguration(elevationStyle: .flat)
       
    case .satellite:
      uiView.preferredConfiguration = MKImageryMapConfiguration()

    case .hybrid:
      uiView.preferredConfiguration = MKHybridMapConfiguration()

    case .satelliteFlyover:
      uiView.preferredConfiguration = MKImageryMapConfiguration(elevationStyle: .realistic)

    case .hybridFlyover:
      uiView.preferredConfiguration = MKHybridMapConfiguration(elevationStyle: .realistic)

    case .mutedStandard:
      uiView.preferredConfiguration = MKStandardMapConfiguration(emphasisStyle: .muted)

    }

    let geocoder = CLGeocoder()
     
    geocoder.geocodeAddressString(searchKey) { placemarks, error in
      if let placemarks,
        let firstPlaceMark = placemarks.first ,
        let location = firstPlaceMark.location {
         
        let targetCoordinate = location.coordinate
         
        print(targetCoordinate)
         
        let pin = MKPointAnnotation()
         
        pin.coordinate = targetCoordinate
         
        pin.title = searchKey

        uiView.addAnnotation(pin)

        uiView.region = MKCoordinateRegion(center: targetCoordinate,
                          latitudinalMeters: 3000.0,
                          longitudinalMeters: 3000.0)
      }
    }
  }
}

Accepted Reply

I'm having the same error but with a MKCoordinateSpan. This is my code:

let span = MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)

...

let currentRegion = MKCoordinateRegion(center: lastCoordinate, span: span)

I hope they will release a fix, right now I have to change the latitude and longitude delta to 0.05 and everything works fine.

Cheers.

  • Thanks for getting back to me. I have entering the code and trying I get an error in the simulator. Get location by keywords and zooming will result in an error😅 I hope the glitch will be fixed.

    pin.coordinate = targetCoordinate pin.title = searchKey uiView.addAnnotation(pin) let coordinateSpan = MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005) uiView.region = MKCoordinateRegion(center: targetCoordinate, span: coordinateSpan)

    Thank you.

  • Thank you! :D

Add a Comment

Replies

I'm having the same error but with a MKCoordinateSpan. This is my code:

let span = MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)

...

let currentRegion = MKCoordinateRegion(center: lastCoordinate, span: span)

I hope they will release a fix, right now I have to change the latitude and longitude delta to 0.05 and everything works fine.

Cheers.

  • Thanks for getting back to me. I have entering the code and trying I get an error in the simulator. Get location by keywords and zooming will result in an error😅 I hope the glitch will be fixed.

    pin.coordinate = targetCoordinate pin.title = searchKey uiView.addAnnotation(pin) let coordinateSpan = MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005) uiView.region = MKCoordinateRegion(center: targetCoordinate, span: coordinateSpan)

    Thank you.

  • Thank you! :D

Add a Comment

This is happening to me as well, these were my deltas, MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01), however, moving them one decimal lower to 0.1 solved my issue and allowed the preview to build as well as the simulator to stop crashing.

Thank you!

This happens in the simulator. I transferred the app to my iPhone and it worked fine.