2016-09-21 61 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) 

}