문제

I would like to remove all annotations from my mapview without the blue dot of my position. When I call:

[mapView removeAnnotations:mapView.annotations];

all annotations are removed.

In which way can I check (like a for loop on all the annotations) if the annotation is not the blue dot annotation?

EDIT (I've solved with this):

for (int i =0; i < [mapView.annotations count]; i++) { 
    if ([[mapView.annotations objectAtIndex:i] isKindOfClass:[MyAnnotationClass class]]) {                      
         [mapView removeAnnotation:[mapView.annotations objectAtIndex:i]]; 
       } 
    }
도움이 되었습니까?

해결책

Looking at the MKMapView documentation, it seems like you have the annotations property to play with. It should be pretty simple to iterate through this and see what annotations you have :

for (id annotation in myMap.annotations) {
    NSLog(@"%@", annotation);
}

You also have the userLocation property which gives you the annotation representing the user's location. If you go through the annotations and remember all of them which are not the user location, you can then remove them using the removeAnnotations: method :

NSInteger toRemoveCount = myMap.annotations.count;
NSMutableArray *toRemove = [NSMutableArray arrayWithCapacity:toRemoveCount];
for (id annotation in myMap.annotations)
    if (annotation != myMap.userLocation)
        [toRemove addObject:annotation];
[myMap removeAnnotations:toRemove];

Hope this helps,

Sam

다른 팁

If you like quick and simple, there's a way to filter an array of the MKUserLocation annotation. You can pass this into MKMapView's removeAnnotations: function.

 [_mapView.annotations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"!(self isKindOfClass: %@)", [MKUserLocation class]]];

I assume this is pretty much the same as the manual filters posted above, except using a predicate to do the dirty work.

이 문제가 있었고 HTTP 요청을 시도하고 결과 메소드를 확인합니다. (여기서는 여기에서) 수정으로 작동하지만 많은 수의 사이트를 한 번에 확인하는 데 다소 느립니다.위와 같이 무효화 된 사이트 캐시 함수를 사용하여 끝내 었습니다.

public bool SPSiteReallyExists(string url) {
    SPSite.InvalidateCacheEntry(new Uri(url), Guid.Empty);
    return SPSite.Exists(uri);
}
.

이 코드는 많은 수개월 동안 생산 중이 었으며 Spsite에는 문제가 없었습니다. 일반적으로 UI가 있지만 때로는 C # API를 통과하는 경우 사이트를 삭제 한 후에 거짓을 반환해야 할 때 true를 반환해야합니다.

이 통화의 사용에 대한 성능에 영향을 미치지 않았으며, 사용하지 않는 것처럼 할당이라고합니다.이 래퍼를 항상 사용하십시오.논리적으로 해당 사이트의 캐시 만 무효화하는 것만으로 생각하지 않습니다.그러나 SharePoint API는 항상 논리를 따르는 것은 아닙니다 ...

shortest way to clean all annotations and preserving MKUserLocation class annotation

[self.mapView removeAnnotations:self.mapView.annotations];
SPSite site;
SPWeb web;
SPSecurity.RunWithElevatedPriviliges(delegate()
{
    site = new SPSite([url]);
    web = site.AllWebs.Add("sitename", "title", "description", 1033, "STS#1", false, false);
});
.

이 트릭을 수행해야합니다. 사이트 이름과 SharePoint가 나머지를 처리합니다.)

it easier to just do the following:

NSMutableArray *annotationsToRemove = [NSMutableArray arrayWithCapacity:[self.mapView.annotations count]];
    for (int i = 1; i < [self.mapView.annotations count]; i++) {
        if ([[self.mapView.annotations objectAtIndex:i] isKindOfClass:[AddressAnnotation class]]) {
            [annotationsToRemove addObject:[self.mapView.annotations objectAtIndex:i]];
            [self.mapView removeAnnotations:annotationsToRemove];
        }
    }

[self.mapView removeAnnotations:annotationsToRemove];

나는이 코드를 보았으며, 자바 스크립트를 도와줍니다.

document.execCommand('enableObjectResizing', false, false);
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top