2011년 1월 24일 월요일

google API search

  • 검색바를 하나 놓으시구 검색버튼이 눌렸을때

    NSString *source = [searchBar text];

    [searchBar resignFirstResponder];
    NSError *error = nil;
    NSStringEncoding encoding;
    NSString *url = [NSString stringWithFormat:@"http://maps.google.co.kr/maps/geo?q=%@&output=csv",
    [source stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:url]
    usedEncoding:&encoding
    error:&error];

  • NSArray *items = [locationStr componentsSeparatedByString:@","];
    CLLocationCoordinate2D mCoordinate;
    if ([items count] >= 4 && [[items objectAtIndex:0] isEqualToString:@"200"]) {
    mCoordinate.latitude = [[items objectAtIndex:2] doubleValue];
    mCoordinate.longitude = [[items objectAtIndex:3] doubleValue];
    }else{
    //검색 실패 일경우
    UIAlertView *view = [[UIAlertView alloc]
    initWithTitle:@"알림"
    message:@"검색어가 부정확 합니다"
    delegate:self
    cancelButtonTitle:@"닫기"
    otherButtonTitles:nil];
    [view show];
    [view release];
    }



  •  [self dropPinAnnotationByCoordinate:mCoordinate];

    위의 드랍핀어노태이션은 제가 만든 함수 이구요
    어노테이션을 놓으시려면 즉 핀을 위치에 지정하게 하시려면
    viewForAnnotation을 정의

댓글 없음: