2012-08-10 46 views
0

在我的didUpdateToLocation方法中,我获取位置更新,但当前位置的移动是一些什么干。MapView上的用户位置更新顺利

这是接收位置更新委托:

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLoc fromLocation:(CLLocation *)oldLoc 
{ 
    MKCoordinateRegion region; 
    region.center.latitude = newLoc.coordinate.latitude; 
    region.center.longitude = newLoc.coordinate.longitude; 
    region.span.latitudeDelta = 0.1; 
    region.span.longitudeDelta = 0.1; 
    [self.mapView setRegion:region animated:YES]; 
} 

能否请你帮我确定如何获得平稳的位置更新?我在网上搜索,发现我们可以在ios5中使用跟踪模式来获得平滑的位置更新。如果是这种情况,那么我应该在当前的代码片段中做出什么改变。

如果我设置 [self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES]; 在视图中没有加载,那么我应该需要在位置更新中再次设置区域? 或者它会自动设置,因为我使用了usertrackingmode?

+0

你可以显示你使用的'CLLocationManager'设置代码吗? – 2012-08-10 05:13:13

+0

in viewDidLoad我输入了下面的代码self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; self.locationManager.distanceFilter = kCLDistanceFilterNone; [self.locationManager startUpdatingLocation]; – Sonal0706 2012-08-10 05:14:43

+0

您可能希望将注释中的代码移至主要问题,以便将来发现此问题的其他人更清楚。 – 2012-08-10 05:23:07

回答

0

设置跟踪模式后,您不需要执行任何手动区域/视图设置。

+0

感谢您的回复。我的应用程序现在正在顺利地跟踪位置。但我没有得到在道路中心的更新位置。 – Sonal0706 2012-08-13 03:29:26

+0

我不明白。你是说你的iPhone不再准确地跟踪你? – Craig 2012-08-13 07:27:36

+0

不,我所得到的位置更新没有出现在道路中心。 – Sonal0706 2012-08-13 09:03:09

0

虽然它会更快耗尽电池(因此除非需要,不应使用它),但如果使用不同的desiredAccuracy,则可能会发现精度会提高。

如果您参考苹果列表Accuracy Constants,您可能会发现kCLLocationAccuracyBestForNavigationkCLLocationAccuracyBest是更好的选择。

+0

好的谢谢你的答复。如果我设置[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];在视图中加载然后我应该需要在位置更新中再次设置区域?或者它会自动设置,因为我使用了usertrackingmode? – Sonal0706 2012-08-10 05:24:33