¿Imagen en lugar de un pin predeterminado en MapKit framework de iPhone?

votos
6

¿Es posible tener nuestra propia imagen en lugar del pin predeterminado en el mapa de MapKit en iPhone?

Estoy trabajando en una aplicación que mostraría las ubicaciones de amigos al igual que Google Latitude y la necesidad de mostrar la imagen de los amigos en sus ubicaciones.

Es posible usar JavaScript Google Map, pero quiero saber si alguien puede dar algún código de muestra para el mapa basado en MapKit.

Publicado el 29/09/2009 a las 15:15
fuente por usuario
En otros idiomas...                            


3 respuestas

votos
14

Sí, es posible. Para eso debes usar MKAnnotationView en lugar de MKPinAnnotationView. y no use la propiedad annotation.animatesDrop.

Aquí está el código de muestra que puede usar en viewForAnnotation,

    annotation = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"try"];
    annotation.canShowCallout = YES;

    annotation.image = [UIImage imageNamed:@"image.png"];


    return annotation;
Respondida el 29/09/2009 a las 15:20
fuente por usuario

votos
2

También puede configurar el cuadro de la imagen. Para que en el código anterior tenemos que hacer estos sencillos cambios.

UIImage *pinImage = [UIImage imageNamed:@"image.png"];

UIImageView *imageView = [[[UIImageView alloc] initWithImage:pinImage] autorelease];

       imageView.frame = CGRectMake(-20, 0, 40, 30);

[annotation addSubview:imageView];

Y tenemos que comentar la línea

// annotation.image = [UIImage imageNamed:@"image.png"];
Respondida el 29/11/2010 a las 07:38
fuente por usuario

votos
0

Mediante el uso de la propiedad lapso puede acercarse fácilmente a sus requieren

MKCoordinateSpan lapso;

MKCoordinateRegion region;


mapView.scrollEnabled=YES;
span.latitudeDelta = 100.0;//more value you set your zoom level will increase
span.longitudeDelta =100.0;//more value you set your zoom level will increase
mapView.showsUserLocation=YES;
region.span = span;


region.center = from.coordinate;
  [mapView setRegion:region animated:YES];
 [mapView regionThatFits:region];
[mapView addAnnotation:from];
Respondida el 25/07/2013 a las 08:39
fuente por usuario

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more