2016-09-21 56 views
0

只需按简单按钮即可对span进行简单编码以放大用户位置。它遵循用户,但需要跨度编码帮助。快速跨度缩放

我用这个ATM

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

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

} 

回答

1

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

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

“拉长”的错误。如何将它们设置为用户位置? – Adam

+0

你可以硬编码当前的经纬度,如果你在模拟器上测试,你需要自己设置。 –

+0

我如何硬拉代码和长?难吗? – Adam

1

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

你需要创建一个区域 - MKCoordinateRegion

获取长期和纬度使用MKCoordinateSpan

例如:

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) 

}