How to search MKMapView with UISearchBar?

后端 未结 6 2244
南旧
南旧 2020-11-28 18:54

I have an application that needs to have a similar search feature like the Apple \"Maps\" application (included with iPhone, iPod Touch and iPad).

The feature in que

6条回答
  •  佛祖请我去吃肉
    2020-11-28 19:36

    Swift version, adapted for iOS 9:

    let geocoder = CLGeocoder()
    geocoder.geocodeAddressString(addressString) { (placemarks, error) in
    
        if let center = (placemarks?.first?.region as? CLCircularRegion)?.center {
    
            let region = MKCoordinateRegion(center: center, span: MKCoordinateSpanMake(0.02, 0.02))
            self.mapView.setRegion(region, animated: true)
        }
    }
    

    based on user1466453's answer.

提交回复
热议问题