Relative Content

Tag Archive for swiftuimapkit

SwiftUI Map zoom to show custom annotations

I’m trying some basic tutorials for testing MapKit. I have added two custom annotations and the map automatically zooms out to show both annotation coordinates, but the annotations views are cut on the left and right margins. Is there a way to define a zoom level to initially show the full annotations views?

Conform to iOS 17.0’s Use Map initializers that take a MapContentBuilder

import MapKit import SwiftUI extension MKCoordinateRegion: Equatable { public static func == (lhs: MKCoordinateRegion, rhs: MKCoordinateRegion) -> Bool { lhs.center.latitude == rhs.center.latitude && lhs.center.longitude == rhs.center.longitude && lhs.span.latitudeDelta == rhs.span.latitudeDelta && lhs.span.longitudeDelta == rhs.span.longitudeDelta } } struct TestMap: View { @State private var region = MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194), span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: […]

How to adjust alignment of `MapCameraPosition ` in iOS 17

Using Xcode 15.4. I want to position and follow the user’s location on a Map, but I want to position the camera “above” the user’s location (or align the user’s location to the bottom of the screen). My view currently looks like this: