如何在swift 2(xcode)中使用mapkit放大位置

时间:2015-10-14 02:50:49

标签: xcode swift location mapkit ios9

当用户输入地址时,我试图放大地图上的一个点,例如,一个无限循环。我希望它放大到街道的位置,但我不能因为上帝的爱让它放大。我已经尝试搞乱该地区,跨度等但没有运气。这是我的代码看起来像(我在视图中没有任何东西加载func)...你会看到我已经注释掉了一些代码,因为我尝试过它并没有发生任何事情。 my code以下是模拟器the output on simulator

上的输出

2 个答案:

答案 0 :(得分:0)

为什么要在func封闭中定义geocodeAddressString

以下代码怎么样?

    geocoder.geocodeAddressString(address, completionHandler: {(placemarks, error) -> Void in
        if (error != nil) {
            print("Error", error)
        }

        if let placemark = placemarks?.first {
            let span = MKCoordinateSpan(latitudeDelta: 0.0001, longitudeDelta: 0.0001)
            let coordinate = placemark.location!.coordinate
            let region = MKCoordinateRegion(center: coordinate, span: span)
            self.mapView.setRegion(region, animated: true)
        }
    })

结果:

enter image description here

答案 1 :(得分:0)

  

var用于范围和区域,而不是let

     

您需要摆脱self

前面的Map.setRegion      

还可以尝试使用更大的数字作为范围坐标,例如0.40.5    或者您仍然可以使用并不重要的0.0001

span = MKCoordinateSpanMake(0.4,0.4)

var region = MKCoordinateRegion(center: **location variable goes in here** , span = span ) 
Map.setRegion(region, animated: true)