2

我有 iPod Touch 2G、iOS 4.2.1,但在从 iOS 3.2 更新软件后,我无法确定设备的位置(使用 Wifi 三角测量)。我的代码:

-(IBAction) naitapraeguneasukoht: (id) sender 
{
     CLLocation*location=[[CLLocation alloc] initWithLatitude:57.797944 longitude:25.04858];
     MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
     region.center = location.coordinate;
     region.span.longitudeDelta = 1.0f;
     region.span.latitudeDelta = 3.8f;

     [self.mapView setRegion:region animated:YES];
     [location release];

     self.locationManager = [[[CLLocationManager alloc] init] autorelease];
     locationManager.delegate = self;
     locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
     [locationManager startUpdatingLocation];
}

- (void) locationManager: (CLLocationManager *) manager didFailWithError: (NSError *) error 
{
    NSString *teade = [[NSString alloc] initWithString:@"Ei õnnestunud asukohta tuvastada"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:trade delegate:nil cancelButtonTitle: @"OK" otherButtonTitles:nil];
    [alert show];
    [teade release];
    [alert release];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta=0.005f;
    span.longitudeDelta=0.005f;
    region.center=newLocation.coordinate;
    region.span=span;
    [mapView setRegion:region animated:TRUE];
}

我收到一条错误消息,提示无法确定位置。定位服务肯定是开启的。

iOS 4.2 模拟器给了我正确的位置,但 iOS 5.0 模拟器给了我 Cupertino。为什么会这样,为什么它不能在我的设备上运行?

4

0 回答 0