문제

iPhone의 MapKit 지도에 기본 핀 대신 자체 이미지를 가질 수 있습니까?

저는 Google Latitude처럼 친구의 위치를 ​​표시하고 친구의 위치에 있는 친구의 이미지를 표시해야 하는 애플리케이션을 개발 중입니다.

JavaScript Google Map을 사용하는 것이 가능하지만 누군가가 MapKit 기반 지도에 대한 샘플 코드를 제공할 수 있는지 알고 싶습니다.

도움이 되었습니까?

해결책

네, 가능합니다.이를 위해서는 MKPinAnnotationView 대신 MKAnnotationView를 사용해야 합니다.Annotation.animatesDrop 속성을 사용하지 마세요.

viewForAnnotation에서 사용할 수 있는 샘플 코드는 다음과 같습니다.

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

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


    return annotation;

다른 팁

이미지의 프레임을 설정할 수도 있습니다.이를 위해 위 코드에서 간단한 변경을 수행해야 합니다.

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

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

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

[annotation addSubview:imageView];

그리고 우리는 그 줄에 주석을 달아야 합니다.

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

범위 속성을 사용하면 요구 사항을 쉽게 확대/축소할 수 있습니다.

MKCoordinateSpan 범위;

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top