UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Best practise to use to store type MKPlacemark in Firestore

Forums > Swift

I am trying to store a user selected location in Firestore but not sure what the best approach to use as MKPlacement is not decodable.

When I perform the search for the location searched for by the user I am using the following model:

struct MapLandmark {

    let placemark: MKPlacemark

    var id: UUID {
        return UUID()
    }

    var name: String {
        self.placemark.name ?? ""
    }

    var title: String {
        self.placemark.title ?? ""
    }

    var coordinate: CLLocationCoordinate2D {
        self.placemark.coordinate
    }
}

And the function:

private func nearByLandmarks(location : String) {

        let request = MKLocalSearch.Request()
        request.naturalLanguageQuery = location

        let search = MKLocalSearch(request: request)
        search.start { (response, error) in
            if let response = response {

                let mapItems = response.mapItems
                self.landmarks = mapItems.map {
                    MapLandmark(placemark: $0.placemark)
                }

            }

        }

    }

What would be the reccomended approach moving forward so I am able to store a copy of this information in Firestore?

Thanks in advance.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.