iOS 5 возвращает неверное местоположение пользователя, а iOS 4 - нет - PullRequest
1 голос
/ 10 декабря 2011

У меня есть 3 iPad:

iPad 3G / WiFi iOS 5.0.1

iPad 2 3G / WiFi iOS 4.3.5

iPad 2 WiFi iOS 5.0.1

Запуск одного и того же кода на всех 3 iPad приводит к тому, что мое местоположение отображается как «Нью-Йорк» на iPad с iOS 5.0.1, а iPad с iOS 4.3.5 возвращает мое правильное местоположение.

В чем может быть причина?

Спасибо!

Код добавлен:

//  AppDelegate.h
//  Created by Michael Superczynski on 8/27/11.
//  Copyright 2011 HyperNova Software. All rights reserved.

#import "Locator.h"
#import <UIKit/UIKit.h>

@interface AppDelegate : NSObject <UIApplicationDelegate>

{
    CLLocationManager *locationManager;
    Locator *locator;
}

@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) Locator *locator;

@end

//  AppDelegate.m
//  Created by Michael Superczynski on 8/27/11.
//  Copyright 2011 HyperNova Software. All rights reserved.

#import "AppDelegate.h"
#import "Locator.h"
#import <MapKit/MapKit.h>

@implementation AppDelegate

@synthesize locationManager;
@synthesize locator;
. . .

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{   
    Locator *aLocator = [[Locator alloc]init];
    locator = aLocator;
CLLocationManager *aLocationManager = [[CLLocationManager alloc] init];
locationManager = aLocationManager;
locationManager.delegate = locator;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 100;
locationManager.purpose = @"This will show your location on the map";
[locator startStandardUpdates];
. . .
}

//
//  Locator.h
//
//  Created by Michael Superczynski on 8/30/11.
//  Copyright 2011 HyperNova Software. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface Locator : NSObject <CLLocationManagerDelegate, MKReverseGeocoderDelegate>
{
    NSString *currentLocation;
    CLLocation *currentCLLocation;
    CLLocationManager *locationManager;
}

@property (nonatomic, strong) NSString *currentLocation;
@property (nonatomic, strong) CLLocation *currentCLLocation;
@property (nonatomic, strong) CLLocationManager *locationManager;

-(void)reverseGeocodeCurrentLocation:(CLLocation *)location;
-(void)startStandardUpdates;

@end

//
//  Locator.m
//
//  Created by Michael Superczynski on 8/30/11.
//  Copyright 2011 HyperNova Software. All rights reserved.
//

#import "AppDelegate.h"
#import <CoreLocation/CoreLocation.h>
#import "Locator.h"

@implementation Locator

@synthesize currentLocation;
@synthesize currentCLLocation;
@synthesize locationManager;

-(id)init
{
    self = [super init];
    if (self) 
    {
        // Initialization code here.
    }
    return self;
}

-(void)startStandardUpdates
{
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [CLLocationManager locationServicesEnabled];
    currentCLLocation = [[CLLocation alloc]init];
    [locationManager startUpdatingLocation];
    float latitude;
    float longitude; 
    if (![CLLocationManager locationServicesEnabled])
    {
        latitude = kDefaultLocationLatitudeA;
        longitude = kDefaultLocationLongitudeA; 
    }
    else
    {
        latitude = (float)locationManager.location.coordinate.latitude;
        longitude = (float)locationManager.location.coordinate.longitude;
    }
    CLLocation *location = [[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
    [self reverseGeocodeCurrentLocation:location];
}

// Delegate method from the CLLocationManagerDelegate protocol.
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
{
    NSDate* eventDate = newLocation.timestamp;
    currentCLLocation = newLocation;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
    newLocation.coordinate.latitude,
    newLocation.coordinate.longitude] argument:nil]; 
    // If it's a relatively recent event, turn off updates to save power
    if ((abs((int)(howRecent))) < 30.0)
        [self reverseGeocodeCurrentLocation:newLocation];
}

-(void)reverseGeocodeCurrentLocation:(CLLocation *)location
{
    MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc]initWithCoordinate:location.coordinate];
    reverseGeocoder.delegate = self;
    [reverseGeocoder start];    
}

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark    
{
    self.currentLocation = [NSString stringWithFormat:@"%@, %@", placemark.administrativeArea, placemark.country];
}

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error 
{
    if ([error code] != kCLErrorLocationUnknown) 
        [locationManager stopUpdatingLocation];
    float latitude = kDefaultLocationLatitudeA;
    float longitude = kDefaultLocationLongitudeA; 
    CLLocation *cLLocation = [[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
}

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error 
{
    if ([error code] != kCLErrorLocationUnknown) 
        [locationManager stopUpdatingLocation];
}
@end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...