我似乎有许多相关的问题,这里发布的有关MKMapView
的许多人。而不是不能得到它放大和显示当前的位置,我似乎无法得到它停止这样做。这里是发生了什么:防止MKMapView不断重新缩放和重新定位到用户位置
- 我启动的应用程序
- 的的MKMapView显示了我的位置,并以蓝点
- 我用我的手指
- 几秒钟后,的MKMapView缩小和远在地图上突然放大早在到中心对我的当前位置再次
我试图告诉我的CLLocationManager
到stopUpdatingLocation
(没有任何影响,因为一个MKMapView
知道如何使用CoreLocation
),我试过告诉MKMapView
到setShowsUserLocation:NO
(根本不显示蓝点,这不是我想要的)。我甚至试图消除我的CLLocationManager
(没有效果)。是什么原因导致这种情况,我该如何阻止它?
是的,我做的设置位置管理的精度和距离-loadView
。我不执行-mapViewDidFinishLoadingMap
:。这是我实现
-locationManager:didUpdateToLocation:fromLocation:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// How many seconds ago was this new location created?
NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];
// CLLocationManagers will return the last found location of the device first,
// you don't want that data in this case. If this location was made more than 3
// minutes ago, ignore it.
if (t < -180)
{
// This is cached data, you don't want it, keep looking
return;
}
[locationManager stopUpdatingLocation];
}
我觉得这是定心你问一下,@Anna·卡列尼娜:
- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)u
{
CLLocationCoordinate2D loc = [u coordinate];
// Display the region 500 meters square around the current location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 500, 500);
[mv setRegion:region animated:YES];
}
你在做什么?在'mapView:didUpdateUserLocation:'?你可以发布该代码吗? – Anna
每次用户位置更改或获取新读数时,都会调用didUpdateUserLocation方法。您可以添加一个bool ivar,您可以在该方法中进行检查/设置,以便只进行一次对中_OR_,您可以根据u.location.horizontalAccuracy或u.location.timestamp有条件地进行居中。 – Anna
好的,这是有道理的,但是...我现在有-mapView:didUpdateUserLocation:有条件地集中,如果u.location.horizontalAccuracy> locationManager.desiredAccuracy,它仍然在发生。如果我扭转了这种情况,我没有获得初始缩放。 – DJHoward