ios - 如何将 map 缩放到我的注释地标 - Swift

标签 ios swift mapkit

我有一个包含所有 MapKit 函数的类,以及另一个我称之为 MapKit 的类。我的目标是提供一个地址(字符串),并且 map 显示一个缩放到该位置的地标。

到目前为止,我设法使 map 正常工作,并且地标位于正确的街道上,但不要缩放到地标位置。

map 声明如下: @IBOutlet var mapPreview: MKMapView!

这是地标的代码。如何缩放到该地标?

    var address = restaurante.rua + " " + restaurante.numero + "," + restaurante.localidade + ", Portugal"
    var geocoder = CLGeocoder()
    geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
        if let placemark = placemarks?[0] as? CLPlacemark {
            self.mapPreview.addAnnotation(MKPlacemark(placemark: placemark))

最佳答案

我建议使用该功能

func showAnnotations(_ annotations: [AnyObject]!,
            animated animated: Bool)

Apple Documentation

关于ios - 如何将 map 缩放到我的注释地标 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32289325/

相关文章:

ios - UIStackView 内容拥抱在 UITableViewCell 中没有按预期工作

swift - 如何在 mapKit 中绘制路线?

ios - 如何删除错误的 GPS 坐标

iphone - 使用 Three20 对超出表格边界的行/单元格进行重新排序时,表格 View 不会滚动

ios - 当我在 iphone 5 屏幕上运行程序时 xcode 看起来像 iphone 4

ios - 从我的 CoreData 获取数据并使用 Swift 将其呈现在 TableView 中时出现 fatal error

ios - 如何使用 Swift 的 Decodable 来解析您只知道或只关心几个字段的任意 JSON 字符串?

json - swift - 访问 JSON 数据

iphone - 选择器添加参数

ios - 在 iOS 中将属性字符串设置为 UILabel