需要建议学习MKMapView和UISearchBar。我需要研究的所有概念是什么?我在哪里可以学习这些概念?

时间:2013-10-25 04:35:45

标签: ios iphone cocoa-touch mkmapview mapkit

我需要做一个IPhone应用程序,我应该在其中实现MKMapView和UISearchBar。如果我在UISearchBox中输入地点的名称,则应返回相关的地点,并且当我们触摸某个地点时,必须执行一次地图注释。为实现它们,我需要研究的所有概念是什么?我在哪里可以学习有关“MKMapView”及相关概念的概念?

请在评论中告诉我一些链接。以编程方式解释并且不使用Interface Builder的页面。

提前致谢。

2 个答案:

答案 0 :(得分:0)

您无需使用Google地图SDK。 使用MapKit.framwork作为苹果自己的库。 如果您没有具体的理由使用Google Map iOS sdk更好地了解MapKit.framework。比较两个框架时有利有弊。但是,由于您处于初始阶段,我建议使用MapKit.framwork。

http://www.raywenderlich.com/21365/

您可以使用以下链接学习UISearchBar的基础知识。

http://programmerstube.com/mobile/objective-c-tutorial/objective-c-iphone-programming-tutorial-uisearchbar

答案 1 :(得分:0)

我写了一个简单的例子。尝试使用这个。

  • (无效)viewDidLoad中 { [super viewDidLoad];

    mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
    mapView.delegate = self;
    mapView.showsUserLocation = YES;
    mapView.zoomEnabled = YES;
    mapView.scrollEnabled = YES;
    mapView.rotateEnabled = YES;
    // mapView.pitchEnabled = YES;
    [self moveMapViewToLocation:mapView.userLocation.location];
    [self zoomMapViewToLocation:mapView.userLocation.coordinate];
    [self.view addSubview:mapView];
    

    } - (无效)zoomMapViewToLocation:(CLLocationCoordinate2D)位置 {     if(location.longitude< = -180 || location.latitude< = -180)     {         返回;     }

    MKCoordinateRegion region;
    MKCoordinateSpan span;
    
    span.latitudeDelta = 0.004;
    span.longitudeDelta = 0.004;
    
    region.span=span;
    region.center=location;
    
    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];
    

    }

    - (无效)moveMapViewToLocation:(CLLocation *)位置 {     MKCoordinateRegion region;

    region.span = mapView.region.span;
    region.center = location.coordinate;
    
    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];
    

    }

    • (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

    }

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {     [self zoomMapViewToLocation:userLocation.coordinate]; }

    • (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views { for(视图中的MKAnnotationView * annotationView) {     if(annotationView.annotation == mv.userLocation)     {         [self zoomMapViewToLocation:mv.userLocation.location.coordinate];    } } }

    • (无效)onGestureEventFire:(ID)发送方 { if(mapView.mapType == MKMapTypeStandard)     mapView.mapType = MKMapTypeSatellite; 其他     mapView.mapType = MKMapTypeStandard; } @end