2011-08-20 5 views

답변

13

LocationManager를 중지했다가 다시 시작하면 장치가 초기 위치를 다시 획득해야합니다.

[locationManager stopUpdatingLocation]; 
[locationmanager startUpdatingLocation]; 
3

내 앱 중 하나에서 같은 문제가 발생했습니다. 실제로 앱 구조를 변경해야했습니다. 이것은 내가 한 것입니다 : 이 클래스에는 public 메서드가 있습니다. - (무효) locateMe; abstract 클래스는이 클래스를 인스턴스화하고 locateMe를 실행할 필요가있다. 그러면 userIsLocated 알림이 방송 될 때. 또 다른 메소드는 결과 좌표를 (CLLocation *) currentLocation에서 가져올 수 있습니다. 하는 .m

#import "ManageUserLocation.h" 

    @implementation ManageUserLocation 

    @synthesize locationManager; 
    @synthesize currentLocation; // Other classes use this to get the coordination even better you can make another method that even dont get the direct access to currentLocation. It is up to you. 

    - (id)init 
    { 
     self = [super init]; 
     if (self) { 
     //[self locateMe]; // Just a hook if you need to run it 
     } 
     return self; 
    } 

    -(void) locateMe { 
     self.locationManager = nil; 
     self.locationManager = [[CLLocationManager alloc] init]; 
     self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; 
     self.locationManager.delegate = self; 
     [self.locationManager startUpdatingLocation]; 
    } 

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
     // User location has been found/updated, load map data now. 
     [self.locationManager stopUpdatingLocation]; 
     currentLocation = [newLocation copy]; 
     // WooHoo Tell everyone that you found the userLocation 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"userLocationIsFound" object:nil]; 
    } 

    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ 
     // Failed to find the user's location. This error occurs when the user declines the location request or has location servives turned off. 
     NSString * errorString = @"Unable to determine your current location."; 
     UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error Locating" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [errorAlert show]; 
     [errorAlert release]; 
     [locationManager stopUpdatingLocation]; 
    } 
    - (void)dealloc { #warning dont forget this :) } 
@end 

희망이 도움말에

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

@interface ManageUserLocation : NSOperation <CLLocationManagerDelegate> { 
    CLLocationManager  *locationManager; 
    CLLocation    *currentLocation; 
} 
@property (nonatomic, retain) CLLocationManager  *locationManager; 
@property (nonatomic, retain) CLLocation   *currentLocation; 

-(void) locateMe; 
@end 

.

0

업데이트를 강제로 적용하는 Apple 지침에 위배됩니다. Apple은 지리적 업데이트가 자동으로 발생하지만 알려지지 않은 시간에 발생한다고 말합니다.

관련 문제