0
 #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)我假设在这种无 wifi/无蜂窝模式下添加了 4 条记录。我可以在地图显示中添加 3 个罚款(但再次与我当前的位置不同的位置)。但是在第四次(或稍后的某个时间),当我访问应该显示地图的屏幕时,它是白色的。这有意义吗。如果您需要更多信息,请询问。谢谢..哦,这一切都在设备上而不是模拟器上。还有它的iOS6。

4

1 回答 1

1

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

于 2013-01-22T21:51:47.620 回答