【发布时间】:2014-03-10 15:45:09
【问题描述】:
我尝试过使用这种方法,但由于某种原因它不会放大当前位置。是不是我做错了什么?
Appdelegate.m
-(void)handleNetworkChange
{
self.reachability = [Reachability reachabilityForInternetConnection];
[self.reachability startNotifier];
NetworkStatus remoteHostStatus = [self.reachability currentReachabilityStatus];
MapViewController *mapViewController = [[MapViewController alloc]init];
if(remoteHostStatus == NotReachable)
{
self.internetReachable = NO;
}
else
{
self.internetReachable = YES;
[mapViewController userLocation];
}
}
MapViewController.m
-(void)userLocation
{
MKCoordinateRegion mapRegion;
mapRegion.center.latitude = self.mapView.userLocation.coordinate.latitude;
mapRegion.center.longitude = self.mapView.userLocation.coordinate.longitude;
mapRegion.span.latitudeDelta = 0.2;
mapRegion.span.longitudeDelta = 0.2;
[self.mapView setRegion:mapRegion animated:YES];
}
【问题讨论】:
-
是您的方法 userLocation 从应用委托调用
-
是的,我可以确认它正在被调用。
-
在哪里显示(呈现)
mapViewController,以及为什么每次调用handleNetworkChange方法时都创建MapViewController的实例? -
我仅以这种方式显示实例作为示例,但我显示 mapviewcontroller 的方式是通过导航控制器而不是通过 appdelegate。
-
首先你可以记录 mapView userLocation 坐标,看看是否有正确的坐标,然后尝试将 deltas 从 0.2 更改为 0.005。
标签: ios objective-c mkmapview mkuserlocation