내 앱 내부에서 핵심 위치 프레임 워크를 사용하고 있습니다. 앱이 처음 시작될 때 didUpdateToLocation 메서드가 두 번 호출됩니다. 위치 관리자 인스턴스를 할당하고 시작하고 startUpdatingLocation을 호출했습니다. 그리고 didUpdateToLocation에서 나는이 함수의 다중 호출을 피할 수 있도록 서버에 현재 위도와 경도를 보내는 다른 함수를 호출하고 있습니까?동일한 기능을 여러 번 호출하지 않으려면 어떻게해야합니까?
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
[self.mapView setShowsUserLocation:YES];
if([CLLocationManager locationServicesEnabled])
{
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
locationManager.distanceFilter = 1000.0f;
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"GPS Disabled" message:@"Enable GPS settings to allow the application to search for your current location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
//Here is didUpdateToLocation method
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
self.lat = newLocation.coordinate.latitude;
self.longi = newLocation.coordinate.longitude;
NSLog(@"Updated Location : lat--%f long--%f",self.lat,self.longi);
[self updateUserLocation];
}
//in this function i am sending the latitude and longitude to server.
-(void)updateUserLocation
{
NSString *urlString = [[NSString stringWithFormat:@"http://appifylabs.com/tracemybuddies/index.php/iphone/updateUserLocation/?userId=1&latitude=%@&longitude=%@",self.lat,self.longi] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[conn url_Connection:urlString withActivityView:self.activityView withParentView:self.view];
}
일단 업데이트 메서드에서 위치를 얻은 경우 업데이트를 중지하는 stopUpdating 메서드를 호출하십시오. – vishy
여기에 코드를 입력하십시오.이 코드는 명확하게 이해할 수 있습니다 .. – Abhishek
내가 필요하기 때문에이 작업을 수행 할 수 없습니다. 현재 위치가 내 앱 내부에서 업데이트되고 현재 위치가 업데이트 될 때마다 서버에 업데이트 된 위도와 경도를 전송합니다. 이 함수는 앱이 처음 시작할 때만 두 번 호출됩니다. 그렇지 않으면 현재 위치가 업데이트 될 때 한 번만 호출됩니다. – iosuser