2011-02-16 2 views
0

을 작동하지 않는 코드는 ADRESS 검색을 수행해야한다. CLLocationCoordinate2D location2 = [self adressLocation가 작동하지 않는 라인을. 그것은 잘못 될 수 무엇 "잘못된 이니셜."말하는?이유는 "CLLocationCoordinate2D LOCATION2 = [자기 adressLocation는"

-(IBAction) search { 
    MKCoordinateRegion region; 
    MKCoordinateSpan span; 
    span.latitudeDelta = 0.4; 
    span.longitudeDelta = 0.4; 

    CLLocationCoordinate2D location2 = [self adressLocation]; 

    region.span = span; 
    region.center = location2; 
    Mark adr = [[Mark alloc] initWithCoordinate:location2]; 
    [mapView addAnnotation:adr]; 
} 

-(CLLocationCoordinate2D) adressLocation { 
    NSString * urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",[suchFeld.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
    NSString * locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:&fileError]; 
    NSArray * listItems = [locationString componentsSeparatedByString:@","]; 
    double latitude2 = 0.0; 
    double longitude2 = 0.0; 
    if ([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) 
    { 
     latitude2 = [[listItems objectAtIndex:2] doubleValue]; 
     longitude2 = [[listItems objectAtIndex:3] doubleValue]; 
    } else { 
     // error  
    CLLocationCoordinate2D location2; 
    location2.latitude = latitude2; 
    location2.longitude = longitude2; 
    return location2; 
} 

답변

0

adressLocation 방법은 아마도 .H 파일에 선언되지 않고 방법을 호출하는 코드 뒤에 정의되어 있기 때문에, 컴파일러가 오류를주는 .H 파일이 추가 :.

-(CLLocationCoordinate2D) adressLocation; 


일부 분리를 문제 :

search 방법에서는 Mark adr = [[Mark alloc]...입니다.
Mark *adr = [[Mark alloc]... (별표 참고)이어야합니다.

또한 search 방법의 경우 행을 addAnnotation 행 다음에 수행해야합니다.

마지막으로 adressLocation은 모든 경우에 값을 반환하지 않습니다.
else 부분에서만 return을 수행합니다. if-part에서도 값을 반환해야합니다.

+1

.h에 추가하는 대신 파일 맨 위에있는 클래스 확장에서이를 선언 할 수 있습니다. 이것은 메소드의 "private"특성을 보존하면서 선언합니다. –

+0

@ 케빈 발라드 : 좋은 지적, 고마워. – Anna