2015-09-10 17 views

回答

1

我想通了就在剛纔,

func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!) { 
    // Define a span (for zoom) 
    let span: MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005) 

    // Get user location 
    let location = CLLocationCoordinate2D(
     latitude: userLocation.coordinate.latitude, 
     longitude: userLocation.coordinate.longitude 
    ) 

    // Get the close region for the user's location 
    // This zooms into the user's tracked location 
    let region = MKCoordinateRegion(center: location, span: span) 
    let adjusted = mapView.regionThatFits(region) 
    mapView.setRegion(adjusted, animated: true) 

    // Here we set the offset of the map to be 75% to the right 
    // and 15% from the top. Gives us a nice top right view. 
    var rect = mapView.visibleMapRect 
    let point = MKMapPointForCoordinate(location) 
    rect.origin.x = point.x - rect.size.width * 0.75 
    rect.origin.y = point.y - rect.size.height * 0.15 
    mapView.setVisibleMapRect(rect, animated: true) 
} 

Pablo答的答案是一個很好的起點,但遺憾的是,它不足以做我正在尋找的東西。

我繼續前進,並在地圖視圖頂部添加了遮罩視圖,以便更好地直觀地瞭解我最終要做什麼樣的UI。

MKMapView Example

0

您可以將像素座標圖,以座標知道在哪裏添加您的腳,每一個地圖區域發生變化時更新:

CGPoint fakecenter = CGPointMake(20, 20); 
CLLocationCoordinate2D coordinate = [mapView convertPoint:fakecenter toCoordinateFromView:mapView]; 
+0

所以這基本上將意味着我將不得不隱藏用戶的位置,但繼續跟隨用戶,並用自己的腳? –

+0

實際上,在你讀兩次你想做的事情之後,你應該能夠得到用戶用戶座標和先前計算出的座標之間的差異,並將該地圖置於'user location - diff'中。 –

+0

以前計算的座標是指虛假中心位置? –