Multiple Locations on Map (using MKMapItem and CLGeocoder)

后端 未结 2 1116
刺人心
刺人心 2020-12-01 15:06

I\'m trying to display multiple locations in MKMapItem. I am getting those locations from a CLGeocoder, unfortunately it only accepts one location.

2条回答
  •  时光说笑
    2020-12-01 16:08

    For Guys looking for Swift Solution:

    func getCoordinate( addressString : String, completionHandler: @escaping(CLLocationCoordinate2D, NSError?) -> Void ){
                let geocoder = CLGeocoder()
                geocoder.geocodeAddressString(addressString) { (placemarks, error) in
                    if error == nil {
                        if let placemark = placemarks?[0] {
                            let location = placemark.location!
                            completionHandler(location.coordinate, nil)
                            return
                        }
                    }
    
                    completionHandler(kCLLocationCoordinate2DInvalid, error as NSError?)
                }
            }
    

    Thanks to Apple. Official doc link

    You can use the snippet in the following way for multiple addresses:

    let address = ["India","Nepal"]
    
    for i in 0..

提交回复
热议问题