簡體   English   中英

如何知道已經使用了哪個注釋?

[英]How to know which annoation has been tapped?

我在做mapview。 在我的應用程序中,有一些代碼可以獲取用戶當前的經緯度位置。 使用此坐標,我正在創建一個肥皂請求。 作為回應,我將獲得位置的信息(郵政編碼,城市,州,國家,坐標)。 我已將此信息保存在NSDictionary中。

這是用於創建注釋的代碼。

MapLocation *annotation = [[MapLocation alloc] initWithCoordinate:location ownerInst:ownerInstitution];
    [mapView addAnnotation:annotation];
    [annotation release];


- (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>) annotation {

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = infoButton;


annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}

當用戶點擊標注中的detaildisclosure按鈕時,這就是委托方法。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

在詳細信息顯示按鈕上,將加載新視圖。 在此新視圖中,將顯示我從服務器檢索到的信息。

到目前為止,一切都很好。 我在地圖中有多個注釋。 但是,當點擊特定注釋時,我將如何實現代碼以顯示與該注釋相關的信息(從服務器獲取)。

我希望我清楚地表達我的問題。 隨時詢問更多細節。

從委托方法獲得的MKAnnotationView *view包含Annotation。 您可以將所有信息存儲在需要顯示的MapLocation類中。

MapLocation *annotation = [[MapLocation alloc] initWithCoordinate:location ownerInst:ownerInstitution];
[mapView addAnnotation:annotation];
[mapView addAdditionalCustomInformation: SomeInfo]; //you need to write your custom methods for that ;)
[annotation release];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM