2012-08-12 7 views

답변

2
  1. 먼저 필요한 프레임 워크 (CoreLocation 및 MapKit)를 가져옵니다.

    #import <Foundation/Foundation.h> 
    
    #import <CoreLocation/CoreLocation.h> 
    
    #import <MapKit/MapKit.h> 
    
    @interface Annotation : NSObject <MKAnnotation> 
    
    @property (nonatomic) CLLocationCoordinate2D coordinate; 
    @property (nonatomic, copy) NSString *title; 
    @property (nonatomic, copy) NSString *subtitle; 
    
    @end 
    
  2. 설치는하는 .m :

    #import "Annotation.h" 
    
    @implementation Annotation 
    @synthesize coordinate, title, subtitle; 
    
    @end 
    
    1. 설정 viewDidLoad

      if ([CLLocationManager locationServicesEnabled]) { 
      
          locationManager = [[CLLocationManager alloc] init]; 
      
          [locationManager setDelegate:self]; 
      
          [locationManager setDesiredAccuracy: kCLLocationAccuracyBestForNavigation]; 
      
          [locationManager startUpdatingLocation]; 
      
          } 
      
          self.mapView.delegate = self; 
      
    2. 그런 다음
    3. 설정의 .H 목적-C NSObject의 클래스 주석을 만들

    4. 설정은 didUpdateToLocation

      // IMPORT ANNOTATION 
      
          - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
      
      
          [locationManager stopUpdatingLocation]; 
      
          double miles = 3.10686; 
          double scalingFactor = ABS((cos(2 * M_PI * newLocation.coordinate.latitude/360.0))); 
      
          MKCoordinateSpan span; 
      
          span.latitudeDelta = miles/69.0; 
          span.longitudeDelta = miles/(scalingFactor * 69.0); 
      
          MKCoordinateRegion region; 
          region.span = span; 
          region.center = newLocation.coordinate; 
      
          [self.mapView setRegion:region animated:YES]; 
      
          Annotation *annot = [[Annotation alloc] init]; 
          annot.coordinate = newLocation.coordinate; 
      
          [self.mapView addAnnotation:annot]; 
      
          } 
      
0

가장 간단한 방법으로지도보기 이동을 위해 MKMapViewYES-showsUserLocation를 설정하고 MKMapViewDelegate

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { 
    MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.location.coordinate, MKCoordinateSpanMake(0.01, 0.01)); 
    [mapView setRegion:region animated:NO]; 
} 

을 구현하는 것입니다 그 위치는 사용자의 위치가 발견되었을 때.

지도 앱처럼 사용자 위치에서지도보기에 파란색 점이 표시됩니다.

관련 문제