由于SKCoordinateRegion

时间:2015-04-22 13:54:25

标签: ios objective-c cllocationmanager skmaps

我有一个奇怪的问题,最近才开始发生,我无法弄清楚原因。

当我用这段代码初始化我的地图时,一切都很完美:

_mapView = [[SKMapView alloc] initWithFrame:CGRectMake( 0.0f, 0.0f,  CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) )];

[self.view insertSubview:_mapView atIndex:0];

_mapView.settings.rotationEnabled = NO;
_mapView.settings.displayMode = SKMapDisplayMode2D;

[SKRoutingService sharedInstance].mapView = _mapView;

但是,当我想放大地图上的某个特定区域时,事情变得很时髦,屏幕只是蓝色。

代码:

[self.locationManager startUpdatingLocation];
_lattitude = self.locationManager.location.coordinate.latitude;
_longitude = self.locationManager.location.coordinate.longitude;
SKCoordinateRegion region;
region.center = CLLocationCoordinate2DMake(_latitude, _longitude);
region.zoomLevel = 14;
_mapView.visibleRegion = region;
[self.locationManager stopUpdatingLocation];

截图:

enter image description here

现在,我想提一下蓝屏只出现在首次发布时。如果我关闭应用程序并再次启动它,地图将正确显示(在模拟器和真实设备上)。

我跟踪了哪一段代码导致了这一点,就是这个:

_mapView.visibleRegion = region;

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

位置经理可能还没有收到它的位置并且给你0,0这是在非洲海岸前的某个地方。海洋=蓝色。

您需要为位置管理员设置一个代理,并等待您的位置的正面修复,然后在地图中显示该区域。在上面的代码中,您可以在启动位置管理器后立即请求该位置。