swift - 当我尝试放大时 map 不断反弹

标签 swift mkmapview

你好,Swift 新手来了。我正在开发 map 应用程序,但我遇到区域跨度问题。我将其更改为 0.05,0.05,我希望它能够放大和缩小。然后找出当我移动时纬度和经度会发生变化。这使得我的 map 在我的代码中不断反弹到 0.05 跨度。

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let latispan = 0.05
    let longspan = 0.05

    let location = locations.last
    let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: latispan, longitudeDelta: longspan))
    self.mapView.setRegion(region, animated: true)
    //labelText.text = "\(location!.coordinate.latitude) , \(location!.coordinate.longitude)"

    labelText.text = "\(region.span.latitudeDelta), \(region.span.longitudeDelta)"
    //self.locationManager.stopUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    print("Errors:" + error.localizedDescription)
}

我尝试获取当前跨度,以便稍后更改我的纬度跨度、长跨度,但我就是找不到方法。

最佳答案

尝试遵循这可能对您有帮助:)

func loadMapData() {

        if let location = AppDelegate.getInstance().newlocation {
            let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
            let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))
            self.map.setRegion(region, animated: true)
        }

        self.map.removeAnnotations(self.map.annotations)
        self.map.showsUserLocation = true
        for retailer in self.liststores {
            let information = MKPointAnnotation()
            information.coordinate = CLLocationCoordinate2D(latitude: retailer.retailer_lat!.doubleValue, longitude: retailer.retailer_lon!.doubleValue)
            information.title = retailer.retailer_name
            information.subtitle = retailer.retailer_addr1! + retailer.retailer_addr2!
            self.map.addAnnotation(information)
        }
    }

关于swift - 当我尝试放大时 map 不断反弹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34669541/

相关文章:

ios - 不要在 MKMapView 放大/缩小时调整注释大小

iOS:使用 OutputStream(url: , append:) 发送大文件(超过 3Gb)时出现问题 => 代码状态 500

ios - swift iOS : How to refactor a lot of conditions for if statement?

swift - 如何使用 Swift Package Manager 更新单个依赖项?

swift - 函数安全地分配一个可选的变量,或者分配默认值如果 nil : Could not cast value of type 'Swift.Int' to 'Swift.String'

Swift FMDB 修饰符

swift - 如何使 map 图钉动画掉落? swift 2.2 iOS 9

iphone - 缩放 MKMapView 以适应折线点

ios - MKAnnotationView 标注中的反转文本

ios - 检测结束拖动/缩放 MKMapView