IanMK2 Blog

현재 위치와 어느한지점을 지도에 뿌리기위해 맵뷰를 쓸일이 생겼다.

사전작업은 다음과 같다.
프레임워크에서 CoreLocation.framework를 추가
헤더는 MapKit/MapKit.h를 추가
일단 원하는 위치에 핀을 박기위한 클래스
///////////////////PlaceMark.h//////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface PlaceMark : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) NSString *title;
@property (nonatomic, assign) NSString *subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D)coordinate;

@end


//////////////////PlaceMark.m/////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface PlaceMark : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) NSString *title;
@property (nonatomic, assign) NSString *subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D)coordinate;

@end



실제 사용소스시
        MKMapView *gmap = [[MKMapView alloc] initWithFrame:self.view.bounds];
gmap.showsUserLocation = TRUE; //자기위치 표시
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.005;//표시되는 영역의 설정 수치가 작을수록 더 확대된다.
span.longitudeDelta= 0.005;
CLLocationCoordinate2D location = gmap.userLocation.coordinate;
location.latitude=[[storedata objectForKey:@"latitude"] floatValue];//GPS좌표경위도설정
location.longitude=[[storedata objectForKey:@"longitude"] floatValue];
region.span = span;
region.center = location;
[gmap setRegion:region animated:TRUE];
[gmap regionThatFits:region];
PlaceMark *placemark = [[PlaceMark alloc] initWithCoordinate:location]; //핀박을위치설정
placemark.title = @"Title"
placemark.subtitle = @"SubTitle";

[gmap addAnnotation:placemark];  //핀을 박아넣는다.
[self.view addSubview:gmap]; //뷰에 추가

[placemark release];
[gmap release];


Posted by IanMK2
NSString * pStr = [[NSString stringWithstring:@"tel:전화번호] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:pStr]];

전화걸때 쓰면 된다. (간단간단)
Posted by IanMK2
-(void)textViewDidBeginEditing:(UITextView *)textView{
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"완료"  style:UIBarButtonSystemItemSave target:self action:@selector(done)];

[self.navigationItem setRightBarButtonItem:doneButton];
[doneButton release];
[scrollview setContentOffset:CGPointMake(0, 190) animated:YES];
}
-(void)done{
[self.navigationItem setRightBarButtonItem:nil];
[self.textview resignFirstResponder];
[scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
}

텍스트뷰에 멀티라인을 입력한 후 편집모드를 나오기 위해 네비게이션에 완료버튼을 추가하고
버튼을 누르면 키보드를 집어넣는 기능이다. 덤으로 스크롤뷰도 스크롤한다.
Posted by IanMK2