2014-10-05 7 views
0

mkmapview에서 여러 위치 핀 점을 얻는 방법.mkmapview에 여러 위치 점을 표시하는 방법

내 현재 위치 내 친구 등록보기.

위치 위도와 경도 값이 있습니다.

아래는 이해를 돕기위한 더미 값입니다.

{ 
friendA: 
{ 
latitude: "12.1234"; 
longtitude: "12.1234"; 
}, 

friendB: 
{ 
latitude: "12.1234"; 
longtitude: "12.1234"; 
}, 

friendD: 
{ 
latitude: "12.1234"; 
longtitude: "12.1234"; 
} 

} 

는지도보기를 만든 PinPointer Marker.png

//와 배치가 위치 와지도보기에 내 모든 친구를 표시하고 싶습니다.

mapView = [[MKMapView alloc] init]; 
mapView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-60); 
mapView.delegate = self; 
mapView.mapType = MKMapTypeStandard; 
mapView.showsUserLocation = YES; 
[self.view addSubview:mapView]; 

MKAnnotation MarkerPin 포인터

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    static NSString *AnnotationViewID = @"annotationView"; 

    MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; 

    if (annotationView == nil){ 
     annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; 
    } 

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

    return annotationView; 
} 

답변

0

당신은 당신의 친구들을 반복 할 필요가 다음 각 항목에 대한 addAnnotation 전화 (당신이 그 (것)들을 배열이나 무엇인가?에 저장해야 할). 같은

뭔가가 :

for (Friend *friend in friends){ 
    CLLocationCoordinate2D coordinate; 
    coordinate.latitude = latitude.doubleValue; 
    coordinate.longitude = longitude.doubleValue; 
    MKPointAnnotation *myAnnotation = [[MKPointAnnotation alloc] init]; 
    myAnnotation.coordinate = coordinate; 
    [mapView addAnnotation:annotation]; 
} 

그런 다음, 당신은 이미 구현 방법, mapView:viewForAnnotation:가 자동으로 호출되는 및 주석이 추가됩니다. 자세한 내용은이 자습서를 확인하십시오. http://www.devfright.com/mkpointannotation-tutorial/