当我尝试放大时,地图会反弹回来

时间:2016-01-08 04:31:33

标签: swift mkmapview

Hello swift新手来了。我在地图应用程序上工作,我遇到区域跨度问题。我将其更改为0.05,0.05,我希望它可以放大和缩小。然后找出我在纬度和经度周围移动时会发生变化。这使我的地图在我的代码中保持反弹到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)
}

我试着获得当前的跨度,所以我可能会改变我的latispan,longspan以后,但我找不到方法。

1 个答案:

答案 0 :(得分:1)

尝试以下操作可能对您有所帮助:)

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)
        }
    }