¿Cómo se muestran las imágenes en lugar de las clavijas en el mapa? Hasta ahora solo puedo agregar pines de barril. Un código de muestra del .m sería de gran ayuda ya que aún soy nuevo en la programación de iOS.iOS MapKit pins personalizados
Respuesta
#pragma mark -
#pragma mark MKMapView delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:@"someImage.png"];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
return nil;
}
EDIT:
poder explicar a todos ustedes acerca de la MKAnnotationView
, pero creo que se encuentra la documentación proporcionada por Apple para ser una explicación mucho mejor que la de cualquier otra fuente. Verifique la sección de visión general en el enlace.
https://developer.apple.com/documentation/mapkit/mkannotationview
funciona. Gracias. ¿podría incluir una breve explicación sobre los parámetros aprobados y cuál es el identificador de la anotación? ¿Es eso similar a la propiedad de etiqueta de .net? – Bahamut
En lugar de usar "someImage.png", en mi requerimiento, tengo que dibujar en UIView y usar [annotationView addSubView: myView]. Funciona bien. Pero no llama a "didSelectAnnotationView" al tocarlo. ¿Nada malo? – Satyam
Puede ser que necesite deshabilitar la interacción del usuario de esa vista. – Robin
Ir al organizador de Xcode y luego ir a la búsqueda de documentación e weathermap se muestra un ejemplo de un mapa con la inclusión de imágenes en anotación.
#pragma mark -
#pragma mark MKMapView delegate
-(void)addAllPinsOnMapView
{
MKCoordinateRegion region = mapViewOffer.region;
region.center = CLLocationCoordinate2DMake(12.9752297537231, 80.2313079833984);
region.span.longitudeDelta= 0.1f;
region.span.latitudeDelta= 0.1f;
[mapViewOffer setRegion:region animated:YES];
mapViewOffer.delegate=self;
arrMapPin=[[NSMutableArray alloc] init];
NSArray *name=[[NSArray alloc]initWithObjects:
@"Title1",
@"Title2",
@"Title3", nil];
NSMutableArray *arrCoordinateStr = [[NSMutableArray alloc] initWithCapacity:name.count];
[arrCoordinateStr addObject:@"12.970760345459,80.2190093994141"];
[arrCoordinateStr addObject:@"12.9752297537231,80.2313079833984"];
[arrCoordinateStr addObject:@"12.9788103103638,80.2412414550781"];
for(int i = 0; i < name.count; i++)
{
NSArray *components = [[arrCoordinateStr objectAtIndex:i] componentsSeparatedByString:@","];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
mapPin.title = [name objectAtIndex:i];
mapPin.coordinate = coordinate;
[mapViewOffer addAnnotation:mapPin];
}
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:
(MKAnnotationView *)view
{
NSLog(@"%@",view.annotation.title);
NSLog(@"%f",view.annotation.coordinate.latitude);
NSLog(@"%f",view.annotation.coordinate.longitude);
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTapped:)];
[view addGestureRecognizer:tapGesture];
}
-(void)calloutTapped:(UITapGestureRecognizer *) sender
{
NSLog(@"Callout was tapped");
MKAnnotationView *view = (MKAnnotationView*)sender.view;
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
//[self performSegueWithIdentifier:@"annotationDetailSegue" sender:annotation];
OfferDetailsViewController *objOfferDetailsViewController = [[OfferDetailsViewController alloc]init];
[self.navigationController pushViewController:objOfferDetailsViewController animated:YES];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)theMapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = @"annotationViewID";
pinView = (MKAnnotationView *)[mapViewOffer dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
}
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"placeholder"];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
return pinView;
}
añade algunas descripciones antes de publicar un fragmento de código largo. –
- 1. iOS Mapkit Llamada personalizada
- 2. ¿Cómo agrego pines personalizados al iPhone MapKit?
- 3. Cómo usar iconos personalizados con mapKit framework?
- 4. Solución Offline MapKit para iOS
- 5. Gradient Polyline con MapKit ios
- 6. ios MapKit animación MKOverlayView pasando al instante
- 7. MapKit en iOS 6 - ¿Cómo encontrar lugares cerca ...?
- 8. iOS 5 MapKit se cuelga con superposiciones cuando zoom/pan
- 9. ¿Cómo hacer botones personalizados en iOS?
- 10. Android Map Zoom para mostrar todos los Pins
- 11. Determinar la distancia usando mapkit
- 12. Recuperar UserLocation Coordinar con MapKit
- 13. ios mapkit cierre las anotaciones de las anotaciones tocando el mapa
- 14. iOS MapKit ¿Cambiar mapview maptype hace que la imagen de anotación cambie a pin?
- 15. Incluyendo datos personalizados en volcados de emergencia de iOS
- 16. ¿Cómo creo dominios de error personalizados para aplicaciones iOS?
- 17. Calcular el radio en metros usando mapkit
- 18. Superposición de radar meteorológico en MapKit
- 19. Xcode - Anotación abierta mediante programación - MapKit
- 20. iPhone MapKit: Accesibilidad de las anotaciones
- 21. MapKit - polylineWithCoordinates interconecta todos los puntos
- 22. /zoom a la función actual ubicación (MapKit)
- 23. Terreno y vista de satélite usando MapKit
- 24. Desarrollo de iPhone - CLLocationManager vs. MapKit
- 25. ¿Cómo abrir invocar MKAnnotationView programmatically? (iPhone, MapKit)
- 26. ¿Cómo coloco un pin con MapKit?
- 27. Un MapKit para Mac OS X?
- 28. MapKit espectáculo de anotación por defecto
- 29. iPhone - MapKit - Buscando ubicaciones y moviendo anotaciones
- 30. eliminar las superposiciones de mapkit en iphone
Una búsqueda poco va un largo camino :) http://stackoverflow.com/questions/4579397/iphone-mapkit-adding-custom-image-and-pins-to-annotations y también: http://stackoverflow.com/questions/7124028/change-pin-design –