2013-05-03 66 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) 

}