地图中添加大头针

利用MKMapView显示自己当前位置的地图一文中介绍了放大地图和显示自己的位置,下面介绍一下在地图自己位置上添加大头针,实现如下所示:

实现的具体过程很简单:

首先实现MKMapViewDelegate协议:

    @interface iphone_MapViewController : UIViewController
    <CLLocationManagerDelegate,MKMapViewDelegate>{
        IBOutlet MKMapView *mapView;
    }

然后添加代码:

    - (void)viewDidLoad {
        [super viewDidLoad];
         self.mapView.delegate=self;
        CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器
        locationManager.delegate=self;//设置代理
        locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别
        locationManager.distanceFilter=1000.0f;//设置距离筛选器
        [locationManager startUpdatingLocation];//启动位置管理器

        MKCoordinateRegion theRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };
        theRegion.center=[[locationManager location] coordinate];
        [locationManager release];
        [mapView setZoomEnabled:YES];
        [mapView setScrollEnabled:YES];
        theRegion.span.longitudeDelta = 0.01f;
        theRegion.span.latitudeDelta = 0.01f;
        [mapView setRegion:theRegion animated:YES];
    }

    - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
    {
        MKPinAnnotationView *pinView = nil;

            static NSString *defaultPinID = @"com.invasivecode.pin";
            pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
            if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                              initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
            pinView.pinColor = MKPinAnnotationColorRed;
            pinView.canShowCallout = YES;
            pinView.animatesDrop = YES;
             [mapView.userLocation setTitle:@"欧陆经典"];
           [mapView.userLocation setSubtitle:@"vsp"];
         return pinView;
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值