2013-09-16 18 views
0

我一直在四處尋找MKMapview的自定義標註的解決方案,我不想將圖像和文本添加到左側或右側附件視圖。我想我寧願創建一個UIAlertView來調出所選映射引腳的所有信息。創建一個UIAlertView一旦地圖引腳被選中

我已經從JSON數據收集地圖上的緯度和長度,並且JSON數據還包含其他信息,例如:電話號碼,網站鏈接等。

我該如何完成將所有這些信息放入一個UIAlertView中,這個UIAlertView是在按下地圖引腳時被調用的?

下面是一些示例代碼:

self.result = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; 

         if(error == nil) 

          self.mapLocations = result; 

         NSLog(@"%@", [result allKeys]); 

         for (NSDictionary *location in self.mapLocations[@"merchants"]) { 

          for (NSDictionary *locations in location[@"branches"]) { 
           NSLog(@"%@",locations); 
           CLLocationCoordinate2D annotationCoordinate = 
           CLLocationCoordinate2DMake([locations[@"latitude"] doubleValue], 
                  [locations[@"longitude"] doubleValue]); 
           Annotation *annotation = [[Annotation alloc] init]; 
           annotation.coordinate = annotationCoordinate; 
           annotation.title = location[@"name"]; 
           annotation.subtitle = locations[@"street"]; 
           [self.mapView addAnnotation:annotation]; 

,這裏是我的MKAnnotationView方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    if([annotation isKindOfClass:[MKUserLocation class]]) { 

     return nil; 
    } 
    MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annoPin"]; 
    MKAnnotationView *view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"annoView"]; 
    if(!view) { 
     view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annoView"]; 
    } 



    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [rightButton addTarget:nil action:@selector(showDetails :) forControlEvents:UIControlEventTouchUpInside]; 
    pinView.animatesDrop = YES; 
    view.rightCalloutAccessoryView = rightButton; 
    view.image = [UIImage imageNamed:@"check.png"]; 
    view.enabled = YES; 
    view.canShowCallout = YES; 
    return view; 
} 

幫助!

回答

0

如果你想在顯示按鈕被按下後顯示UIAlertView,你應該拿出關於分配一個動作到該按鈕的線路並實現– mapView:annotationView:calloutAccessoryControlTapped:。只要你的類被設置爲地圖的委託,那麼該函數將被調用,你可以從那裏創建你的UIAlertView。關於該功能的參數是annotationView,您可以從中獲得MKAnnotation,並且應該附加所有細節。