Post

Replies

Boosts

Views

Activity

Forward Geocoding: Using getCoordinates() function to create MKMapItem
Hello, I have successfully used the getCoordinates() function provided by Apple Documentation to convert an address to coordinates. I created my own struct for a Pin that includes name, latitude, and longitude as properties. I am able to add Markers to my map using these three properties. My problem is that I'd like to use these Markers to pull up further information, such as lookaround views. To use these API call functions, I need to provide an MKMapItem as an argument to the mapItem parameter. MKLookAroundSceneRequest(mapItem: MKMapItem) I'm having trouble using the MKMapItem documentation to understand how to make my own MKMapItems. If I try using the autocomplete in XCode, I can get this: MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: latitude, longitude: longitude))) Is it possible to add a name when instantiating a new MKMapItem? From the documentation, it seems like name is a property of MKPlacemark, but I can't get this to work. Should I alter the getCoordinates() function to return the entire placemark instead of just the coordinates? Any guidance would be much appreciated! Thanks!
2
1
513
Jan ’24
ShareLink print PNG failing in SwiftUI iOS17
Hello, I'm trying to capture a .png of a view in my application. ImageRenderer is producing this .png file and is able to pass it to Messages and Mail successfully. However, when I press "print" in the ShareLink dialog, the dialog just disappears and nothing happens. If I save that file to the device, then open the photo from the Photos or Files app, the print dialog works. A thread on StackOverflow suggests writing the .png file as data to the documents directory, then passing the URL to the image file as the item within the ShareLink. I haven't been able to get this to work - it just passes a 151 byte URL file. Am I doing something incorrectly? Is this an error within SwiftUI? Thanks for your guidance. @MainActor func render() { let renderer = ImageRenderer(content: PrintView(route: $route)) renderer.scale = displayScale if let uiImage = renderer.uiImage { renderedImage = Image(uiImage: uiImage) } } @State private var renderedImage = Image(systemName: "photo") ShareLink("Export", item: renderedImage, preview: SharePreview(Text("Shared image"), image: renderedImage))
0
0
276
Feb ’24
Disable tapping on hidden MapKit Annotation Titles
Hello, I'm working on a SwiftUI/MapKit project. It uses a custom annotation to mark zip codes on the map. I have an onTapGesture configured to run a custom function when the user clicks on the RoundedRectangle content included in the Annotation. I'm using the .annotationTitles(.hidden) modifier on the Annotation so that the title is not shown below my custom annotation. However, when I click below my annotation (where the hidden title text would be) the normal MapKit selection behavior executes. My project has Markers on the map in which I do want this behavior. It pulls up a half sheet detail view for the Marker. It does not make sense for this half sheet detail view to be displayed when tapping on a zip code. I tried using a ZStack with a transparent rectangle offset to drop below my annotation (yellow in screenshot), and included the same onTapGesture with custom function for this. My hope was that the transparent (yellow) RoundedRectangle would override the behavior of clicking on the hidden title. This didn't work. Any ideas? Thanks for your help!
1
0
475
Feb ’24