2011-04-18 5 views
0

사용자의 모바일 위치가 변경되었는지 30 초인지 여부를 확인해야하는 애플리케이션이 있습니까? 30 초 후에 변경되지 않으면 사용자가 다른보기로 이동하고 가 변경되면 사용자는 모바일 위치의 좌표가 30 초 동안 변경되었다는 메시지를 받게됩니다.아이폰 코어 위치

timer90 내 view.Please이 나를 도울 친구의 이름을 여기에 ...

-(void)time 
{ 

    for(int i = 0; i<= timeremaining ;i++) 
    { 
     if (new1 == old) 
     { 
      if(timeremaining == 1) 
      { 
       Timer90 *timerview = [[Timer90 alloc] initWithNibName:@"Timer90" bundle:nil]; 
       [self.navigationController pushViewController:timerview animated:YES]; 

      } 

     } 
     else 
     { 
      [NSTimer cancelPreviousPerformRequestsWithTarget:self selector:@selector(time) object:nil]; 
     } 

     timeleft.text = [NSString stringWithFormat:@"%d",timeremaining]; 

    } 
    timeremaining--; 

} 
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 

    new1 = newLocation; 
    old=oldLocation; 

    latitude = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.latitude]; 
    longitude = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.longitude]; 
    accuracy = [[NSString alloc] initWithFormat:@"%g",newLocation.horizontalAccuracy]; 

    if(oldLocation == NULL) 
    { 
     oldLocation == newLocation; 
    } 

} 

을 나는이 코드를 사용하고 있지만 아무것도하지 않습니다 ... 어떤 도움을 이해할 수있을 것이다.

답변

0

내가 알아 차 렸던 두 가지. 전체 이슈 일 수도 있고, 일부 일 수도 있습니다.

번호 1

if(oldLocation == NULL) 
{ 
    oldLocation == newLocation; 
} 

oldLocation == newLocation 설정하지 않습니다 서로 (하나 등호)가 필요하고이 같은 객체가 아니라 멤버 포인터에 매개 변수 포인터를 할당하는 동일한 두. 기능 1의

new1 is set to point at Object B 
old is set to point at Object A 
if(Object A is NULL) 
    oldLocation and newLocation both point at Object B 

값을 오래된이 NULL의 경우 동일한 개체로 설정되지 않습니다 예를 들어, oldLocation 점이라면, didUpdateToLocation:fromLocation:의 시작 부분에서 B를 개체에과를 newLocation 점 개체 수 있습니다. 당신이 new1old가 같은 개체를 가리키는 경우 확인하려는 time에서

time의 번호 2.

를 확인하는 것입니다 어느. 반드시 두 객체가 같은 위치를 나타내는 경우는 아닙니다. oldLocation이 null이고 함께 설정되는 경우이 검사는 통과 할 수 있습니다 ... 그러나 CoreLocation이 업데이트 방법을 몇 번 호출하고 정확도가 향상되는 경우가 더 많으며 두 가지 별도의 객체가 표시됩니다 같은 위도/경도 위치.

CLLocation getDistanceFromLocation: 방법을 사용하여 인접 지역을 비교해야합니다.

희망이 도움이됩니다!

0

아마도 카운터와 initialLocation을 속성에 추가 한 후 첫 번째 업데이트 후 30 초 후에 위치를 비교하지만, 전체 메서드에 나이 확인을 추가하면 도움이 될 것이라고 생각합니다. 그래서 당신은 아주 오래된 데이터 포인트와 비교하지 않습니다.

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
    { 
    if(self.counter==0){ 
    self.intialLocation=newLocation; 
    self.counter=1; 
    } 
NSTimeInterval age = [initialLocation.timestamp timeIntervalSinceNow]; 
     if(age>30) 
     { 
    self.counter=0; 
    if(newLocation.latitude==initialLocation.latitude&&newLocation.longitude==initialLocation.longitude){ 
    Timer90 *timerview = [[Timer90 alloc] initWithNibName:@"Timer90" bundle:nil]; 
    [self.navigationController pushViewController:timerview animated:YES]; 
    } 
    } 
    } 
+0

WD의 distanceFromLocation에 대한 의견은 내 정확한 비교 대신 현명 할 것입니다. –