2013-05-03 42 views
0

我有地圖視圖,它設置爲放大用戶當前位置。問題是,如果用戶在查看地圖時更改位置,則會放大回當前位置。這使得我無法使用我計劃要做的功能。我將在地圖上有多個引腳,但如果位置發生變化,用戶將無法查看所有這些引腳。即使當我的設備坐在我的桌子上時,位置也會不斷變化,因此地圖始終將用戶從他們正在查看的地圖的任何部分帶回到其當前位置的縮放視圖。有沒有人有任何想法呢?放大當前位置在地圖視圖

- (void)foundLocation:(CLLocation *)loc 
{ 
    CLLocationCoordinate2D coord = [loc coordinate]; 

    // Zoom the region to this location 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 250, 250); 
    [worldView setRegion:region animated:YES]; 

    [activityIndicator stopAnimating]; 
    [locationManager stopUpdatingLocation]; 
} 

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 
{ 
    CLLocationCoordinate2D loc = [userLocation coordinate]; 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250); 
    [worldView setRegion:region animated:YES]; 
} 
+0

停止移動第一事件後的地圖......你應該在獲取用戶位置後定位地圖。如果您需要幫助,請顯示您如何定位它的代碼。 – iwasrobbed 2013-05-03 22:51:06

回答

2

的問題是這些行:

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250); 
[worldView setRegion:region animated:YES]; 

也就是說,與250,250變焦倍率縮放視圖返回到用戶的位置。所以如果你不希望在用戶移動視圖後縮放視圖,不要這樣做!

0

我們可以停止接收當前的位置是第一次,

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 
{ 
    CLLocationCoordinate2D loc = [userLocation coordinate]; 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250); 
    [worldView setRegion:region animated:YES]; 
    [locationManager stopUpdatingLocation]; 
    locationManager.delegate = nil; 
} 
+0

它不起作用。 – user3722523 2014-11-26 22:15:12

+0

如果您停止更新位置和無委託它永遠不會放大到您提供的區域。 – realtimez 2015-09-19 13:09:24

0

放大到當前位置與斯威夫特:

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 

    let locValue:CLLocationCoordinate2D = manager.location!.coordinate 
    let region : MKCoordinateRegion = MKCoordinateRegionMakeWithDistance(locValue, 250,250) 
    self.mapView.setRegion(region, animated: true) 

}