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.

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.
Oct 13, 2025 ship-a-tonswiftcamp notes
Camp Notes Won a OneSignal Boost Award at Shipaton
Camp Notes placed 5th in the OneSignal Boost Award category at RevenueCat's Shipaton hackathon. This post covers what Shipaton is, why I entered, how I implemented OneSignal for notifications and emails, and what I learned from competing against over 800 entries.