2012-07-15 4 views
1

사용자가 버튼을 클릭 할 때 현재지도가 있습니다.iOS xcode지도 확대

지도를 확대하고 사용자가 버튼을 클릭 할 때 어떻게 확대 할 것인지 애니메이션을 적용하는 방법은 무엇입니까?

여기에는 주요 파일과 헤더 파일이 있습니다. 또한 현재 위치를 표시하려면 어떻게해야합니까? 질문의 두 번째 부분에 대한 사전 기본 파일

@synthesize map; 


//Add Map overlay 

-(MKOverlayView*)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay{ 



    MKCircleView* circleView =[[MKCircleView alloc] initWithOverlay:overlay]; 

    circleView.strokeColor = [UIColor blueColor]; 

    circleView.fillColor = [UIColor redColor]; 

    return circleView; 



} 


-(IBAction)onLocationButtonTop:(id)sender { 





    UIBarButtonItem* b = (UIBarButtonItem*) sender; 

    int tag = b.tag; 



    float latitude = 40.0; 

    float longitude = -75.0; 



    if(tag == 1){ 

     latitude = 57.15;longitude = -2.15; 

    } 

    else if(tag == 2){ 

     latitude = 39.91;longitude = 116.41; 

    } 

    else{ 

     latitude = -1.46;longitude = -48.48; 

    } 



    CLLocationCoordinate2D x; 

    x.latitude = latitude; 

    x.longitude = longitude; 









    MKCoordinateSpan z; 

    z.latitudeDelta = 0.25; 

    z.longitudeDelta = 0.25; 



    MKCoordinateRegion y; 

    y.center = x; 

    y.span = z; 



    map.region = y; 

    [map addOverlay:[MKCircle circleWithCenterCoordinate:x 

               radius:1000]]; 



} 

시간 파일

#import <UIKit/UIKit.h> 

#import <MapKit/MapKit.h> 


@interface MapExampleK2ViewController : UIViewController <MKMapViewDelegate> 



@property (strong,nonatomic) IBOutlet MKMapView* map; 


-(IBAction)onLocationButtonTop:(id)sender; 



@end 

답변

1

에서

덕분에 당신은 당신에게 현재 위치를 확인하고 때 위치 업데이트 setRegion를 사용하는 CLLocationManager를 사용할 수 있습니다. http://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010726에 게시 된 지역 코드를 참조 할 수 있습니다.

아래 코드는지도에서 현재 위치로 포커스를 설정하는 기능입니다.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
   NSLog(@"didUpdateToLocation %@ from %@", newLocation, oldLocation); 
    
       if (oldLocation == nil) { 
       // Zoom to the current user location. 
       MKCoordinateRegion userLocation = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 1500.0, 1500.0); 
       [regionsMapView setRegion:userLocation animated:YES]; 
   } 
} 
+0

http://stackoverflow.com/questions/13325434/center-maps-in-ios-programming –

관련 문제