2012-04-03 6 views
1

두 가지 질문이 있습니다. (처음) 나는 iPhone이 움직일 때마다 경고 상자가 나타나서 그들이 있던 위치의 경도와 그들이 현재있는 위도를 보여주기 위해 노력하고있다. 이것은 내가 작업중인 더 큰 프로젝트의 일부분을 테스트하기위한 것입니다. 문제는 경고 상자가 전혀 나타나지 않는다는 것입니다. 위치 관리자가 새 위치를 가져 오면 경고 상자에 위치를 표시해야하는 대리인이 실행되지만 아무 일도 일어나지 않는다고 생각했습니다. 대리인을 여기누구나 CLLocationManager를 사용하여 나를 도울 수 있습니까?

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

됩니다 : 여기

내가 위치 관리자를 설정하고있어 어떻게

(둘째) 내가 추적 할 수있어 만족 해요 일단
-(void) locationmanager: (CLLocationManager *) manager 
     didUpdateToLocation: (CLLocation *) newLocation 
     fromLocation: (CLLocation *) oldLocation 
{ 
    float oldlat; 
    float oldlng; 
    float lat; 
    float lng; 
    NSDate *oldtime; 
    NSDate *newtime; 

    lat = newLocation.coordinate.latitude; 
    lng = newLocation.coordinate.longitude; 
    newtime = newLocation.timestamp; 
    oldlat = oldLocation.coordinate.latitude; 
    oldlng = oldLocation.coordinate.longitude;  
    oldtime = oldLocation.timestamp; 

    NSNumber *oldlong = [NSNumber numberWithFloat:oldlng]; 
    NSNumber *newlat = [NSNumber numberWithFloat:lat]; 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:oldlong 
          message:newlat 
          delegate:self 
          cancelButtonTitle:@"Cancel" 
          otherButtonTitles:@"Submit",nil]; 
    [alert show]; 

새롭고 오래된 latlng은 데이터를 저장하는 가장 좋은 방법을 아는 사람이 있습니까? 내가 sqlite, 코어 데이터를 연구하고, 그냥 배열을 사용하여,하지만 난 아직도 의심의 여지가 가장 좋은 방법은 lat, lng, 타임 스탬프와 사용자 이름을 저장하는 약 200 번 하루에 약 200 사용자에게 보낸 다음 서버로 보냅니다.

저는 이것이 긴 질문 이었지만 모든 통찰력은 크게 감사 할 것입니다!

+0

두 번째 질문에 핵심 날짜를 사용하고 싶습니다. 첫 번째 정보 - 변수의 가치는 무엇입니까? 특히, newLocation.coordinate와 oldLocation.coordinate? – TommyG

+0

솔직히 말해서 위임 객체에서 경고를 표시 할 수 있는지 확신 할 수 없습니다 ... 부모 객체에 UIAlertView를 표시하려고 했습니까? – TommyG

+1

또한 경고에는 문자열을 취하는 제목과 메시지가 있습니다. 거기에 NSNumber가 있습니다. 나는 이것이 심지어 컴파일된다는 것에 놀랐다. –

답변

0

확인. 제대로 당신이 initWithTitlemessage 매개 변수 유형 NSString의이고 당신이 전달하는 것은 NSNumber 그렇게 두 를 취할 것입니다 볼 수 UIAlertView 매개 변수를 이해하려고하면

UIAlertView *alert = [[UIAlertView alloc] 
         initWithTitle:oldlong 
         message:newlat 
         delegate:self 
         cancelButtonTitle:@"Cancel" 
         otherButtonTitles:@"Submit",nil]; 

: 응용 프로그램이이 라인에 충돌하지 않았는지 정말 놀랐입니다 위도와 경도에 대해서는 NSString을 입력하고이를 매개 변수로 전달하십시오.

NSString *long1=[[NSString alloc]initWithFormat:@"%f",oldlong]; 
NSString *lat1=[[NSString alloc]initWithFormat:@"%f",newlat]; 

UIAlertView *alert = [[UIAlertView alloc] 
         initWithTitle:long1 
         message:lat1 
         delegate:self 
         cancelButtonTitle:@"Cancel" 
         otherButtonTitles:@"Submit",nil]; 

그러나 당신이 당신의 상호 작용을 각 2 잠금을 경고 팝업까지해야합니다 있도록 끊임없이 호출되는 것으로 didUpdateToLocation에 경고를 표시하는 것은 좋은 생각되지 않습니다. 이 코드가 저에게 효과적 이었지만. 스크린 샷을 살펴보십시오.

enter image description here

+0

"이 코드가 저에게 효과가 있었지만"라고 말할 때. 당신이 쓴 코드에 대해 이야기하고 있습니까? 나는 당신이 말한 모든 변화를 시도했지만 여전히 걷고있을 때 경고 상자가 나타나지 않습니다. 흠 .. – michael03m

+0

그 이유는 내가 스크린 샷을 증거로 올린 이유입니다. :-)) –

+0

그래, 코딩마다 변경 한 다음 도망갔습니다. –

관련 문제