tiene saber pencil cuanta conectar como carga bateria apple iphone mkmapview mkannotation

iphone - saber - ¿Cómo eliminar todas las anotaciones de MKMapView sin eliminar el punto azul?



como conectar apple pencil (7)

¿No es más fácil hacer lo siguiente?

//copy your annotations to an array NSMutableArray *annotationsToRemove = [[NSMutableArray alloc] initWithArray: mapView.annotations]; //Remove the object userlocation [annotationsToRemove removeObject: mapView.userLocation]; //Remove all annotations in the array from the mapView [mapView removeAnnotations: annotationsToRemove]; [annotationsToRemove release];

Me gustaría eliminar todas las anotaciones de mi vista de mapa sin el punto azul de mi posición. Cuando llamo:

[mapView removeAnnotations:mapView.annotations];

Se eliminan todas las anotaciones.

¿De qué manera puedo verificar (como un bucle for en todas las anotaciones) si la anotación no es la anotación del punto azul?

EDITAR (He resuelto con esto):

for (int i =0; i < [mapView.annotations count]; i++) { if ([[mapView.annotations objectAtIndex:i] isKindOfClass:[MyAnnotationClass class]]) { [mapView removeAnnotation:[mapView.annotations objectAtIndex:i]]; } }


Es más fácil hacer lo siguiente:

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];


Mirando la documentación de MKMapView , parece que tienes la propiedad de anotaciones para jugar. Debería ser bastante simple recorrer esto y ver qué anotaciones tiene:

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

También tiene la propiedad userLocation que le proporciona la anotación que representa la ubicación del usuario. Si pasa por las anotaciones y recuerda todas ellas que no son la ubicación del usuario, puede eliminarlas usando el método removeAnnotations: :

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];

Espero que esto ayude,

Sam


Para Swift 3.0

for annotation in self.mapView.annotations { if let _ = annotation as? MKUserLocation { // keep the user location } else { self.mapView.removeAnnotation(annotation) } }


Si te gusta rápido y simple, hay una manera de filtrar una matriz de la anotación MKUserLocation. Puede pasar esto a la función removeAnnotations: de MKMapView.

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

Supongo que esto es casi lo mismo que los filtros manuales publicados anteriormente, excepto que se usa un predicado para hacer el trabajo sucio.


forma más corta de limpiar todas las anotaciones y preservar la anotación de clase MKUserLocation

[self.mapView removeAnnotations:self.mapView.annotations];


for (id annotation in map.annotations) { NSLog(@"annotation %@", annotation); if (![annotation isKindOfClass:[MKUserLocation class]]){ [map removeAnnotation:annotation]; } }

Me modifiqué así