没有单元/ wifi连接的MKMapview无法在设备上正确显示

时间:2013-01-22 19:47:19

标签: ios mkmapview coordinates cllocationmanager

 #define LOCATION_DISTANCE 80.4672
 - (void)viewDidLoad
{
     [super viewDidLoad];
     ....some computation
     locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager startUpdatingLocation];

    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 360.0*NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [locationManager stopUpdatingLocation];

    });
     ..........some more computation
 }
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{

  CLLocation *obj = [locations lastObject];
  if (obj.coordinate.latitude != 0 && obj.coordinate.longitude != 0 )
{
    CLLocationCoordinate2D currrentCoordinates ;
    currrentCoordinates.latitude = obj.coordinate.latitude;
    currrentCoordinates.longitude = obj.coordinate.longitude;
 if(obj.horizontalAccuracy>0 && obj.horizontalAccuracy<100){
            self.turnedOffLocationServices =YES;
                [locationManager stopUpdatingLocation];

        } .... more computation
  [self setUpMap:currrentCoordinates];
}
 - (void)setUpMap:(CLLocationCoordinate2D)currentCoordinates
{
      MKCoordinateRegion extentsRegion = MKCoordinateRegionMakeWithDistance(currentCoordinates, LOCATION_DISTANCE, LOCATION_DISTANCE);

MKMapView *mvMap = [[MKMapView alloc] initWithFrame:CGRectMake(20, 594, 360, 347)];
mvMap.delegate = self;
[mvMap setRegion:extentsRegion animated:YES];
mvMap.mapType = MKMapTypeSatellite;
mvMap.autoresizingMask = UIViewAutoresizingNone;
//mvMap.showsUserLocation = YES;
NSLog(@"the current lat is %f", currentCoordinates.latitude);
NSLog(@"the current long val is %f", currentCoordinates.longitude);

[self.scrollView addSubview:mvMap];

ITMAnnotation *annotation = [[ITMAnnotation alloc] initWithCoordinate:currentCoordinates addressDictionary:nil];
annotation.title = @"Drag to Move Pin";
annotation.subtitle = [NSString stringWithFormat:@"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude];
NSLog(@"subtitle change at 314");

[mvMap addAnnotation:annotation];
self.tempMapView = mvMap;
}

所以我有viewDidLoad创建位置管理器。我认为应该使用didUpdateLocations。我用这个坐标调用setUpMap方法,我在ipad屏幕的左下角得到一张地图。 我的问题是:1)当处于无wifi /小区模式时,我没有得到准确的位置。它的方式。但我手动输入坐标(有文本字段,这将采取这种坐标)它工作,并显示位置。 2)我在这个no-wifi / no cell模式中添加了4个记录。我可以添加3罚款地图显示(但我的当前位置再次有不同的位置)。但是在第4次(或稍后的某个时间),当我访问屏幕时,地图应该显示为白色。这有意义吗?如果您需要更多信息,请询问。谢谢..哦,这一切都在设备上不是模拟器。它的iOS6。

1 个答案:

答案 0 :(得分:1)

电池和GPS在同一芯片上,因此关闭电池会关闭GPS。如果您只想停止数据传输但仍需要GPS,则可以在网络设置下关闭移动数据。您仍然可以拨打电话,但您的设备无法下载任何内容(如果您也关闭了wifi)。