현재 사용자 위치를 가져와야하지만 변경되었는지 여부는 알 수 없습니다. CLLocationManager에서 강제로 위치 업데이트를 요청할 수 있습니까? 아니면 다른 방법이 있습니까?사용자 위치를 강제로 업데이트하는 방법은 무엇입니까?
3
A
답변
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은 지리적 업데이트가 자동으로 발생하지만 알려지지 않은 시간에 발생한다고 말합니다.
관련 문제
- 1. graphviz에서 모서리 위치를 강제로 지정하는 방법은 무엇입니까?
- 2. matplotlib에서 플롯을 강제로 업데이트하는 방법
- 3. 사용자 정의 컨트롤의 위치를 얻는 방법은 무엇입니까?
- 4. 안드로이드에서 Google지도로 사용자 위치를 공유하는 방법은 무엇입니까?
- 5. mapkit에서 사용자 위치를 표시하는 방법은 무엇입니까?
- 6. ajax 페이지 삽입 후 yui 메뉴 위치를 업데이트하는 방법은 무엇입니까?
- 7. 안드로이드에서 특정 시간 이후에 위치를 업데이트하는 방법은 무엇입니까?
- 8. 창 위치를 얻고 다른 창을 업데이트하는 방법은 무엇입니까?
- 9. 웹 참조 위치를 업데이트하는 방법
- 10. Tix.ComboBox의 텍스트를 업데이트하는 방법은 무엇입니까?
- 11. 사용자 IP 주소를 사용하여 사용자 위치를 얻는 방법은 무엇입니까?
- 12. NSString을 업데이트하는 방법은 무엇입니까?
- 13. 파일을 업데이트하는 방법은 무엇입니까?
- 14. 조건을 업데이트하는 방법은 무엇입니까?
- 15. 주소록을 업데이트하는 방법은 무엇입니까?
- 16. 모델을 업데이트하는 방법은 무엇입니까?
- 17. ios를 업데이트하는 방법은 무엇입니까?
- 18. 맞춤지도에서 위치를 표시하는 방법은 무엇입니까?
- 19. JFreeChart에서 차트를 업데이트하는 방법은 무엇입니까?
- 20. SQL 서버 : 강제로 백업/복원 위치를 지정하십시오.
- 21. RoR에서 스키마 버전을 수동으로 업데이트하는 방법은 무엇입니까?
- 22. 강제로 사용자 로그 아웃
- 23. dbpath 매개 변수를 강제로 저장하는 방법은 무엇입니까?
- 24. 모든 WPF 사용자 컨트롤에서 데이터 소스를 업데이트하는 방법은 무엇입니까?
- 25. 사용자 작업없이 타사 Android 응용 프로그램을 업데이트하는 방법은 무엇입니까?
- 26. ASyncTask를 사용하여 사용자 지정 ListView에서 ImageView를 업데이트하는 방법은 무엇입니까?
- 27. 업데이트 패널 외부에있는 경우 사용자 콘텐트의 내용을 업데이트하는 방법은 무엇입니까?
- 28. Android 연락처를 업데이트하는 방법은 무엇입니까?
- 29. RPM 버전을 업데이트하는 방법은 무엇입니까?
- 30. splitViewController에서 detailView를 업데이트하는 방법은 무엇입니까?