zoukankan      html  css  js  c++  java
  • MKMapView指定坐标添加大头针

    #import <UIKit/UIKit.h>
    #import <MapKit/MapKit.h>

    @interface UserLocationViewController : UIViewController<MKMapViewDelegate>{

        MKMapView *mapView;
        UIButton *btn;
    }
    @property(nonatomic,retain) MKMapView *mapView;
    @property(nonatomic,retain) UIButton *btn;
    -(void)btnPressed:(id)sender;
    @end
         

         - (void)viewDidLoad {
         mapView=[[MKMapView alloc]initWithFrame:CGRectMake(10100300100)];
         mapView.scrollEnabled=NO;
         [mapView setDelegate:self];
         //设置地图中心
         CLLocationCoordinate2D coordinate;
         coordinate.latitude = 23.134844f;
         coordinate.longitude = 113.317290f;
         MKPointAnnotation *ann = [[MKPointAnnotation alloc] init];
         ann.coordinate = coordinate;
         [ann setTitle:@"天河城"];
         [ann setSubtitle:@"购物好去处"];
         //触发viewForAnnotation
         [mapView addAnnotation:ann];
          //添加多个
         
    //[mapView addAnnotations]
        
         
         
         
         
    //设置显示范围
         MKCoordinateRegion region;
         region.span.latitudeDelta = 0.001;
         region.span.longitudeDelta = 0.001;
         region.center = coordinate;
         // 设置显示位置(动画)
         [mapView setRegion:region animated:YES];
         // 设置地图显示的类型及根据范围进行显示
         [mapView regionThatFits:region];
        

         [self.view addSubview:mapView];
         
         btn=[[UIButton alloc]initWithFrame:CGRectMake(10100300100)];
         [btn setTag:1];
         [btn setBackgroundColor:[UIColor clearColor]];
         [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
         [self.view addSubview:btn];
     
         [super viewDidLoad];
     }
    - (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;
        return pinView;
    }
    -(void)btnPressed:(id)sender
    {
        [sender setHidden:YES];
        [self.mapView setFrame:CGRectMake(00320480)];
    }

  • 相关阅读:
    SAP MM 启用批次管理的物料MB21创建预留单据时批次号可以为空!
    强化学习十大原则
    新手必看:生成对抗网络的初学者入门指导
    华为云总裁郑叶来:易获取、用得起、方便用的算力是人工智能发展的关键
    贝叶斯、香农、奥卡姆合写博客「机器学习是什么」
    诗人般的机器学习,ML工作原理大揭秘
    为什么AI的翻译水平还远不能和人类相比?
    2018-8-10-wpf-DoEvents-
    2018-2-13-win10-uwp-iot
    2019-9-11-.NET-Standard
  • 原文地址:https://www.cnblogs.com/bandy/p/2395409.html
Copyright © 2011-2022 走看看