Swift跨度变焦

时间:2016-09-21 11:32:44

标签: ios swift

需要对跨度进行简单编码,以便在按下按钮时缩放用户位置。它遵循用户,但需要跨度编码帮助。

我使用这个atm

@IBAction func Refreshbutton(sender: AnyObject) {
//Navigationsknappen

    Mapview.userTrackingMode = .Follow
    self.Locationmanager.stopUpdatingLocation()

}

2 个答案:

答案 0 :(得分:1)

我的理解是,它不是那么简单 -

您需要创建一个区域--MKCoordinateRegion

使用MKCoordinateSpan获取long和lat

示例:

func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool) {


    //Get the location you need the span zoom 

    let location = CLLocationCoordinate2D(

        //getPropertyLocation.latitude/longitude already set to CLLocationDegrees in a prior process.
        latitude: self.getPropertyLocation.latitude ,
        longitude: self.getPropertyLocation.longitude
    )

    // Get the span that the mapView is set to by the user. "propertyMapView" is the MKMapView in this example.
    let span = self.propertyMapView.region.span


    // Setup the region based on the lat/lon of the property and retain the span that already exists.
    let region = MKCoordinateRegion(center: location, span: span)

    //Center the view with some animation.
    mapView.setRegion(region, animated: true)

}

答案 1 :(得分:1)

此代码可能会对您有所帮助。

let span = MKCoordinateSpanMake(0.075, 0.075)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude:lat, longitude: long), span: span)
mapView.setRegion(region, animated: true)