2012-09-03 11 views
-5
CLLocation *userLoc = mapView.userLocation.location; 
    CLLocationCoordinate2D userCoordinate = userLoc.coordinate; 

    NSLog(@"user latitude = %f",userCoordinate.latitude); 
    NSLog(@"user longitude = %f",userCoordinate.longitude); 

    mapView.delegate=self; 

위의 코드는 무엇을 의미합니까? 나는이 코드가 무엇을 사용하는지 알지 못하기 때문에 한 줄씩 설명 할 필요가 없다.누구든지이 코드의 기능을 알고 있습니까?

답변

1

먼저, 이런 종류의 질문에 대답하기 위해 사과 워드 프로세서를 파는 법을 배워야한다. 보통 XXX 클래스 참조 또는 XXX 개발자 가이드를 검색하여 시작합니다.

mapview는 MKMapView 개체입니다. 여기를 참조하십시오 : http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html

userLocation은 사용자의 현재 위치를 반환합니다. 그 문서에서 :

userLocation 
The annotation object representing the user’s current location. (read-only) 

@property(nonatomic, readonly) MKUserLocation *userLocation 

다음 코드는 사용자 위치의 좌표를 가져오고 위도와 경도를 기록합니다.

마지막으로 위임을 자체로 설정하면이 클래스는 MKMapViewDelegate 프로토콜의 콜백을 구현합니다. 그 문서에서 :

What exactly does delegate do in xcode ios project? 그래서 콜백을 사용하면지도보기의 파이프 라인 실행에 코드를 끼어 할 수 있으며 viewForAnnotation 같은 데이터를 제공하기 위해 :

delegate 
The receiver’s delegate. 

@property(nonatomic, assign) id<MKMapViewDelegate> delegate 
Discussion 
A map view sends messages to its delegate regarding the loading of map data and changes in  the portion of the map being displayed. The delegate also manages the annotation views used to highlight points of interest on the map. 

The delegate should implement the methods of the MKMapViewDelegate protocol. 

대리자가 무엇인지 여기를 참조하십시오.

http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intf/MKMapViewDelegate

:

그리고 여기가 MKMapVeiwDelegate에 문서 (당신을위한 콜백지도보기)입니다

관련 문제