Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MKMapView上的自定义注释_Ios_Objective C_Mkmapview - Fatal编程技术网

Ios MKMapView上的自定义注释

Ios MKMapView上的自定义注释,ios,objective-c,mkmapview,Ios,Objective C,Mkmapview,我用MKPLaceMark填充我的地图,带有特定的地址,这些标记对应于会议 我正在尝试自定义一个与下次会议对应的地点标记 这是我的密码: // Function to add all pin corresponding to all meeting. - (void) addAllPins { _myMap.delegate = self; // Get all key of meeting NSArray* allKey = [[VSDataProvider shar

我用
MKPLaceMark
填充我的地图,带有特定的地址,这些标记对应于会议

我正在尝试自定义一个与下次会议对应的地点标记

这是我的密码:

// Function to add all pin corresponding to all meeting.
- (void) addAllPins {
    _myMap.delegate = self;

    // Get all key of meeting
    NSArray* allKey = [[VSDataProvider sharedManager].startEvents allKeys];

    for (NSDate *date in allKey) {
        for (FFEvent *event in [[VSDataProvider sharedManager].startEvents objectForKey:date]) {

            // Retrieve with CLGeocoder the latitude and longitude with address of event
            NSString *localisation = [NSString stringWithFormat:@"%@ %@ %@ %@",event.street,event.zipCode,event.city,event.country];

            CLGeocoder *geocoder = [[CLGeocoder alloc] init];
            [geocoder geocodeAddressString:localisation completionHandler:^(NSArray *placemarks, NSError *error) {
                if (placemarks && placemarks.count > 0) {
                    CLPlacemark *topResult = [placemarks objectAtIndex:0];
                    MKPlacemark *place = [[MKPlacemark alloc] initWithPlacemark:topResult];
                    [arrayWithAllLocation addObject:place];
                    [self addPinWithTitle:event.street AndCoordinateLongitude:place.coordinate.longitude AndCoordinateLatitude:place.coordinate.latitude];
                }

                [self getCoordinateNexEvent:^{
                    for (MKPlacemark *mark in arrayWithAllLocation) {
                        if (mark.coordinate.latitude ==  _coordinateNextEvent.latitude && mark.coordinate.longitude == _coordinateNextEvent.longitude) {
                            MKAnnotationView *test = [[MKAnnotationView alloc]initWithAnnotation:mark reuseIdentifier:@"nextEvent"];
                            test.annotation = mark;
                            test.image = [UIImage imageNamed:@"Meeting.png"];
                            [_myMap addAnnotation:test.annotation]; 
                        }
                    }
                }];
            }];
        }
    }
}

// Retrieve coordinate for the next meeting
- (void) getCoordinateNexEvent :(void (^)(void))afterAll {
    FFEvent *event = [VSDataProvider sharedManager].nextEvent;
    CLGeocoder *geocoder = [[CLGeocoder alloc]init];
    NSString *localisation = [NSString stringWithFormat:@"%@ %@ %@ %@",event.street,event.zipCode,event.city,event.country];
    [geocoder geocodeAddressString:localisation completionHandler:^(NSArray *placemarks, NSError *error) {

        if (placemarks && placemarks.count > 0) {
            CLPlacemark *topResult = [placemarks objectAtIndex:0];
            placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
            _coordinateNextEvent.latitude = placemark.coordinate.latitude;
            _coordinateNextEvent.longitude = placemark.coordinate.longitude;
        }

        afterAll();
    }];
}

// This method add a Pin with the title and coordinate
- (void) addPinWithTitle : (NSString*)title AndCoordinateLongitude : (double)coordinateLongitude AndCoordinateLatitude : (double)coordinateLatitue {
    MKPointAnnotation *mapPin = [[MKPointAnnotation alloc]init];
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(coordinateLatitue, coordinateLongitude);
    mapPin.title = title;
    mapPin.coordinate = coordinate;
    [self.myMap addAnnotation:mapPin];
}

- (void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {    
    MKCoordinateRegion region;
    MKCoordinateSpan span;

    span.latitudeDelta = 0.5;
    span.longitudeDelta = 0.5;

    CLLocationCoordinate2D location;
    location.latitude = userLocation.coordinate.latitude;
    location.longitude = userLocation.coordinate.longitude;

    region.span = span;
    region.center = location;

    [_myMap setRegion:region animated:YES];
}
当我使用

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

    __block MKAnnotationView *annotationWithNextEvent;

    annotationWithNextEvent = (MKAnnotationView*) [_myMap dequeueReusableAnnotationViewWithIdentifier:@"nextEventAnnotation"];

    if (!annotationWithNextEvent) {

        annotationWithNextEvent = [[MKAnnotationView alloc] initWithAnnotation:placemark reuseIdentifier:@"nextEventAnnotation"];
    }
    annotationWithNextEvent.image = [UIImage imageNamed:@"Meeting.png"];
    annotationWithNextEvent.annotation = annotation;
    return annotationWithNextEvent;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
__块MKAnnotationView*注释与下一个事件;
annotationWithNextEvent=(MKAnnotationView*)[\u myMap dequeueReusableAnnotationViewWithIdentifier:@“NextEventNotation”];
如果(!annotationWithNextEvent){
annotationWithNextEvent=[[MKAnnotationView alloc]initWithAnnotation:placemark reuseIdentifier:@“NextEventNotation”];
}
annotationWithNextEvent.image=[UIImage ImageName:@“Meeting.png”];
annotationWithNextEvent.annotation=注释;
返回带有下一个事件的注释;
}
所有注释都是图像,我不想要这个


我希望我很清楚

您应该为它创建如下子类:

@interface MeetingPointAnnotation : MKPointAnnotation
@property (strong, nonatomic) NSString *customData;
@end
然后检查它:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MeetingPointAnnotation class]]) {
        __block MKAnnotationView *annotationWithNextEvent;
        annotationWithNextEvent = (MKAnnotationView*) [_myMap dequeueReusableAnnotationViewWithIdentifier:@"nextEventAnnotation"];
        
        if (!annotationWithNextEvent) {
            annotationWithNextEvent = [[MKAnnotationView alloc] initWithAnnotation:placemark reuseIdentifier:@"nextEventAnnotation"];
        }
        
        annotationWithNextEvent.image = [UIImage imageNamed:@"Meeting.png"];
        annotationWithNextEvent.annotation = annotation;
        return annotationWithNextEvent;
    }
    return nil;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
if([annotation IsKindof类:[MeetingPointAnnotation类]]){
__块MKAnnotationView*注释与下一个事件;
annotationWithNextEvent=(MKAnnotationView*)[\u myMap dequeueReusableAnnotationViewWithIdentifier:@“NextEventNotation”];
如果(!annotationWithNextEvent){
annotationWithNextEvent=[[MKAnnotationView alloc]initWithAnnotation:placemark reuseIdentifier:@“NextEventNotation”];
}
annotationWithNextEvent.image=[UIImage ImageName:@“Meeting.png”];
annotationWithNextEvent.annotation=注释;
返回带有下一个事件的注释;
}
返回零;
}
这将仅自定义该类型的注释

此外,您的代码可能与
CLGeocoder
有关,因为它可能会大量使用它。阅读文档:

应用程序应该了解如何使用地理编码。每个应用程序的地理编码请求都有速率限制,因此在短时间内发出过多请求可能会导致某些请求失败。(当超过最大速率时,地理编码器将向关联的完成处理程序返回一个值为kCLErrorNetwork的错误对象。)以下是有效使用此类的一些经验法则:

  • 对于任何一个用户操作,最多发送一个地理编码请求

  • 如果用户执行多个涉及对同一位置进行地理编码的操作,请重用初始地理编码请求的结果,而不是为每个操作启动单个请求

  • 如果要自动更新用户的当前位置(例如,当用户移动时),则仅当用户移动了相当长的距离并且经过了合理的时间后,才发出新的地理编码请求。例如,在典型情况下,每分钟不应发送多个地理编码请求

  • 不要在用户无法立即看到结果时启动地理编码请求。例如,如果应用程序处于非活动状态或处于后台,则不要启动请求