posts

How to get the current MKCoordinateRegion from a MapCameraPosition

Struggled with this a bit, so figured I would write how I did this.

Goal to achieve: Get the MKCoordinateRegion of the map I’m looking at.

What I tried and did not work:

struct MapSearchView: View {
	@State private var position = MapCameraPosition.automatic
	@State private var mapRegion: MKCoordinateRegion = .init()

	var body: some View {
		Map(position: $position)
		.onChange(of: position) {
			print(position.region)
		}
  }
}

This would always print nil even though it’s supposed to be the current region.

What I ended up getting to work:

struct MapSearchView: View {
	@State private var position = MapCameraPosition.automatic
	@State private var mapRegion: MKCoordinateRegion = .init()

	var body: some View {
		Map(position: $position)
		.onMapCameraChange { mapCameraUpdateContext in
			mapRegion = mapCameraUpdateContext.region
		}
  }
}

I had to use the specific onMapCameraChange to get the region and then update a state variable. I can then use that however I want.

May 13, 2026 swiftcore dataswift concurrency
Stop Using @MainActor as a Threading Fix for Core Data async/await
Using `@MainActor` to silence Core Data concurrency errors keeps service-layer work on the main thread. Learn how `newBackgroundContext()` and `context.perform` create a safer async/await pattern.
Nov 9, 2025 swiftswift testing
How to run Swift Tests Serially across files
Here's how I am running Swift Tests serially. Note, this is using Swift Testing.
Oct 16, 2025 ship-a-tonswiftcamp notes
Camp Notes's First Paywall Experiment
Starting my first paywalll experiment for Camp Notes.