2014-10-05 84 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"; 
} 

} 

想表明我對MapView的各界朋友與有位置 與PinPointer Marker.png

//創建的MapView配售。

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/

相關問題