iOS 地图 自定义以及添加锚点

来源:互联网 发布:社交网络的发展现状 编辑:程序博客网 时间:2024/05/29 02:05

//联系人:石虎  QQ: 1224614774昵称:嗡嘛呢叭咪哄


//自定义添加锚点

- (void)clickLongPress:(UILongPressGestureRecognizer *)longPress {

    CGPoint point = [longPress locationInView:mapView];

    CLLocationCoordinate2D coord = [mapView convertPoint:point toCoordinateFromView:mapView];

    CLLocation *location = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude];

    MKPointAnnotation *annocation = [[MKPointAnnotation alloc] init];

     annocation.coordinate = coord;

      annocation.title = @"我的锚点";

      [mapView addAnnotation:annocation];

}

 //代理方法   签协议 MKMapViewDelegate

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{

        static NSString *annoid = @"str";

        MKAnnotationView *annoView = [mapView dequeueReusableAnnotationViewWithIdentifier:annoid];

    if (!annoView) {

        annoView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annoid];

    }

        annoView.image = [UIImage imageNamed:@"1"];

        return annoView;

}

谢谢!!!

阅读全文
1 0
原创粉丝点击