Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am displaying a map in a view showing a pin location of an address.

Here's what I've got:

import Combine
import CoreLocation
import MapKit
import SwiftUI
struct MapViewLocation: Identifiable {
    let id = UUID()
    var coordinate: CLLocationCoordinate2D
struct MapViewSmall: View {
    @State var address: String
    @State private var mapCoordinate: CLLocationCoordinate2D? = nil
    @State private var mapIsLoading: Bool = true
    @State private var mapLocations: [MapViewLocation] = []
    @State private var mapRegion: MKCoordinateRegion = MKCoordinateRegion()
    @State private var mapSuccess: Bool = false
    var body: some View {
        ZStack {
            if mapIsLoading {
                ProgressView()
                    .progressViewStyle(CircularProgressViewStyle())
                    .scaleEffect(0.8)
            } else {
                if self.mapSuccess {
                        coordinateRegion: $mapRegion,
                        interactionModes: [.pan],
                        annotationItems: mapLocations,
                        annotationContent: { location in
                            MapPin(
                                coordinate: self.mapCoordinate ?? CLLocationCoordinate2D(),
                                tint: .red
                    .frame(width: 100, height: 100)
                    .cornerRadius(9)
                    .onTapGesture {
                        let request = MKLocalSearch.Request()
                        request.naturalLanguageQuery = self.address
                        let search = MKLocalSearch(request: request)
                        search.start { response, error in
                            if let response = response {
                                let mapItem = MKMapItem(placemark: response.mapItems[0].placemark)
                                mapItem.name = self.address
                                mapItem.openInMaps(launchOptions: [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving])
                } else {
                    Image(systemName: "mappin.slash.circle")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: 100, height: 100)
                        .foregroundColor(.red)
        .onAppear {
            self.mapIsLoading = true
            Task {
                await self.makeMap()
func getLocation(address: String, completion: @escaping (_ location: CLLocationCoordinate2D?) -> Void) {
        let geocoder = CLGeocoder()
        geocoder.geocodeAddressString(address) { (placemarks, error) in
            if let error = error {
                print(error.localizedDescription)
                completion(nil)
                return
            guard let placemarks = placemarks,
            let location = placemarks.first?.location?.coordinate else {
                completion(nil)
                return
            completion(location)
    func makeMap() async {
        // Convert the address
        self.getLocation(address: self.address) { location in
            // Handle Bad Address Errors
            if location == nil {
                self.mapSuccess = false
                self.mapIsLoading = false
                return
            self.mapCoordinate = CLLocationCoordinate2D(
                                    latitude: location?.latitude ?? 0.0,
                                    longitude: location?.longitude ?? 0.0
            // Set the Region
            self.mapRegion = MKCoordinateRegion(
                                center: self.mapCoordinate ?? CLLocationCoordinate2D(),
                                span: MKCoordinateSpan(
                                    latitudeDelta: 0.01,
                                    longitudeDelta: 0.01
            // Create the MapViewLocation
            self.mapLocations.append(
                MapViewLocation(
                    coordinate: self.mapCoordinate ?? CLLocationCoordinate2D()
            // Set the Loading State
            self.mapSuccess = true
            self.mapIsLoading = false
struct TestView: View {
    var body: some View {
        MapViewSmall(address: "1 Infinite Loop, Cupertino CA 95014, United States")

The errors in the console when I go to the view are:

2023-01-05 16:22:05.512925-0600 BLAH[14113:3111741] [Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":{"floor":2147483647,"lifespan":-1,"rawLat":0,"integrity":0,"referenceFrame":"Unknown","lon":0,"speed":-1,"type":"Unknown","altitude":0,"rawCourse":-1,"confidence":0,"suitability":{"type":"decode failure","raw value":1797990240,"expected type":"CLClientLocationSuitability"},"ellipsoidalAltitude":0,"timestamp":-1,"rawReferenceFrame":"Unknown","lat":4.9406564584124654e-324,"verticalAccuracy":-1,"rawLon":0,"horizontalAccuracy":-1,"speedAccuracy":-1,"courseAccuracy":-1,"fromSimulationController":false,"course":-1}}

2023-01-05 16:22:05.588983-0600 BLAH[14113:3111741] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""

2023-01-05 16:22:05.875299-0600 BLAH[14113:3111397] [PipelineLibrary] Mapping the pipeline data cache failed, errno 22

I also tried rewriting the functions using Combine to see if that helped and nothing changed so I reverted back.

This all works and the user experience is great, but I would very much like to resolve the errors and understand what I'm doing wrong.

I did. I am not using a simulator, I am using a real device. The solution that was presented discussed things that are not present when presenting a map, so it didn't seem like the correct solution. – kittonian Jan 5 at 22:58 You are checking for nil location, but you should also check for horizontalAccuracy that is negative. “A negative value indicates that the latitude and longitude are invalid.” – Rob Jan 5 at 23:15 Appreciated but the latitude and longitude are not invalid. As I stated, the view works as it should. It's just throwing the errors in console which is what I'm trying to resolve. You can see in the code that the Map() doesn't even show until the function has completed and the mapSuccess variable is set to true. My guess is it's something in the makeMap function since it's running onAppear of the view, but I haven't been able to solve it. – kittonian Jan 5 at 23:44 It looks as though it received a location with a latitude and longitude that are exactly zero. This could be caused by a problem with the location services on the device, or by an issue with the location handling code. – Mark McKeon Jan 6 at 9:51

Remove the Task wrapper around the makeMap() function, because it is not necessary.

Add a onLongPressGesture modifier to the Map view, so that it can handle long press gestures.

Wrap the makeMap() function in a DispatchQueue.main.async block, to ensure that it is called on the main thread. This should fix the "Mapping the pipeline data cache failed, errno 22" error.

 .onAppear {
        self.mapIsLoading = true
        DispatchQueue.main.async {
            self.makeMap()
                Just tried and no, it doesn't solve the pipeline error. I don't want a long press gesture, just a tap. Not looking to change the way the page works, just solve the console errors.
– kittonian
                Jan 6 at 14:58

The error you're seeing is nothing to do with displaying a map, it's generated when doing the geocoding. It seems like the geocoder likes to know where you are when it is geocoding, presumably so it can order results somehow. If your app asks for in-use location permissions, the warning goes away.

If you get console warnings you don't understand, it's always a good idea to set a breakpoint and step through the code to find out exactly where the error is generated.

Incidentally, you can rewrite getLocation like this:

func getLocation(address: String) async -> CLLocationCoordinate2D? {
    let geocoder = CLGeocoder()
        let marks = try await geocoder.geocodeAddressString(address)
        return marks.first?.location?.coordinate
    } catch {
        return nil

And makeMap() like this:

@MainActor
func makeMap() async {
    // Convert the address
    let location = await getLocation(address: self.address)
    // Handle Bad Address Errors
    guard let location = location else {
        self.mapSuccess = false
        self.mapIsLoading = false
        return
    self.mapCoordinate = location
    // Set the Region
    self.mapRegion = MKCoordinateRegion(
        center: location,
        span: MKCoordinateSpan(
            latitudeDelta: 0.01,
            longitudeDelta: 0.01
    // Create the MapViewLocation
    self.mapLocations.append(MapViewLocation(coordinate: location))
    // Set the Loading State
    self.mapSuccess = true
    self.mapIsLoading = false

Call it all from .task instead of onAppear:

.task {
    await self.makeMap()

Which makes your code a little cleaner.

Unfortunately, the same console errors appear. Your code works the same as mine did, but I still have the same error issues. Also, I never need to know where the user is so I don't ask for location permissions. This map is only for displaying an address that the user creates. Think of it like how Apple creates their contact info card and shows a small map of the address. I am working on a private/secure app so tracking the user's location would be a bad thing. – kittonian Jan 6 at 16:15 The console message is caused by the lack of location permissions, nothing else. If you don't want to ask for permissions, then you can just ignore the console message, I don't think there's much else you can do. – jrturton Jan 6 at 16:44 That's no problem. If it is literally console noise because I am not tracking the user's location (i.e. asking them for location permissions), that's totally cool. What about the pipeline error? Is that also the same issue? – kittonian Jan 6 at 16:54 I didn't see the pipeline error on my testing, but unfortunately the Xcode console seems to get noisier with every release, it makes it hard to find legitimate problems. I don't think you need to worry about this one. – jrturton Jan 9 at 9:35

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.