Ios 添加自定义注释接点

Ios 添加自定义注释接点,ios,objective-c,mkmapview,mapkit,Ios,Objective C,Mkmapview,Mapkit,我正在尝试在多段线的起点和终点添加自定义注释接点。但我不知道该怎么做。这是我的地图的图像 我想在多段线的起点或终点添加绿色注释接点 这是我的密码 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { if (annotation==mapView.userLocation) { MKAnnotationView

我正在尝试在多段线的起点和终点添加自定义注释接点。但我不知道该怎么做。这是我的地图的图像

我想在多段线的起点或终点添加绿色注释接点

这是我的密码

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if (annotation==mapView.userLocation) {

        MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"currAnno"];

        if (annotationView == nil) {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currAnno"];
        }

        annotationView.canShowCallout=YES;
        annotationView.image = [UIImage imageNamed:@"mapPin.png"];

        return annotationView;


    }else{

        static NSString *viewId = @"MKAnnotationView";
        MKAnnotationView *annotationView = (MKAnnotationView*)
        [mapView dequeueReusableAnnotationViewWithIdentifier:viewId];

        if (annotationView == nil) {
            annotationView = [[MKAnnotationView alloc]
                              initWithAnnotation:annotation reuseIdentifier:viewId];
        }

        annotationView.canShowCallout=YES;
        annotationView.image = [UIImage imageNamed:@"mapPin.png"];//set your image here
        return annotationView;
    }

}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
if(注释==mapView.userLocation){
MKAnnotationView*annotationView=(MKAnnotationView*)[mapView出列重用AnnotationViewWithIdentifier:@“currAnno”];
如果(注释视图==nil){
annotationView=[[MKAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“currAnno”];
}
annotationView.canShowCallout=是;
annotationView.image=[UIImage ImageName:@“mapPin.png”];
返回注释视图;
}否则{
静态NSString*viewId=@“MKAnnotationView”;
MKAnnotationView*annotationView=(MKAnnotationView*)
[mapView dequeueReusableAnnotationViewWithIdentifier:viewId];
如果(注释视图==nil){
annotationView=[[MKAnnotationView alloc]
initWithAnnotation:annotation重用标识符:viewId];
}
annotationView.canShowCallout=是;
annotationView.image=[UIImage ImageName:@“mapPin.png”];//在此处设置图像
返回注释视图;
}
}

您需要创建两个注释:一个注释以多段线的起点为坐标,另一个注释以多段线的终点为坐标。将这两个注释添加到地图中

注释视图以相应注释的坐标为中心。如果希望图像中绿色管脚的底部显示在注释的坐标处(而不是管脚图像的中心),则需要使用
MKAnnotationView
对象的
centerOffset
属性向上移动图像:

annotationView.canShowCallout=YES;
annotationView.image = [UIImage imageNamed:@"mapPin.png"];
// Move the pin image up 20 points to place the bottom of the pin
// at the annotation coordinate (adjust the value -20 to suit)
annotationView.centerOffset = CGPointMake(0, -20);
此示例将注释视图图像上移20点(负y值将图像上移)。然而,你应该为你的图像使用一个合适的负值,而不是-20,比如减去图像高度的一半或者任何你认为合适的值