문제 설명
Mapview Xcode에서 위치 업데이트 (Update Location in Mapview Xcode)
현재 프로젝트에서.
사용자가 50미터
이동할 때마다 사용자의 위치가 필요합니다.
그래서 기본적으로 50마다 애플리케이션을 연 후 meter
변경 Objective c
에서 웹 서비스를 호출하려면 사용자 위치가 필요합니다. 또한 응용 프로그램이 백그라운드 상태일 때 동일한 프로세스를 실행하고 싶습니다.
미리 감사합니다
참조 솔루션
방법 1:
- You have to make object of CLLocationManager when application starts and set it's delegate
Now add the delegate of CLLocationManagaer that is didUpdateToLocation and add the following code in that.
CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];
if(meters==50) { // CALL YOU WEBSERVICE }
</ol>
Add the below code to get user's current location
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
방법 2:
set your location track in
//create location manager object
locationManager = [[CLLocationManager alloc] init];
//there will be a warning from this line of code
[locationManager setDelegate:self];
//and we want it to be as accurate as possible
//regardless of how much time/power it takes
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
//set the amount of metres travelled before location update is made
[locationManager setDistanceFilter:50];
and add
if ([CLLocationManager locationServicesEnabled]) {
[self.locationManager startUpdatingLocation];
}
Update
‑(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *location = locations.lastObject;
NSLog(@"%@", location.description);
//In here you get all details like
NSLog(@"latitude = %@",location.coordinate.latitude);
NSLog(@"longitude = %@",location.coordinate.longitude);
NSLog(@"altitude = %@",location.altitude);
NSLog(@"horizontalAccuracy = %@",location.horizontalAccuracy);
NSLog(@"verticalAccuracy = %@",location.verticalAccuracy);
NSLog(@"timestamp = %@",location.timestamp);
NSLog(@"speed = %@",location.speed);
NSLog(@"course = %@",location.course);
}
(by Maulik Patel、Jaimish、Anbu.Karthik)