Ios 高德地圖 地圖上添加多個圖釘 怎麼在複用隊列中知道我單擊的是哪一個圖釘

來源:互聯網
上載者:User

標籤:高德地圖   資訊   

//建立圖釘對象    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];    //插入圖釘的位置    pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.989631, 116.481018);    //圖釘的標題    pointAnnotation.title = @"方恒國際";    //圖釘的子標題    pointAnnotation.subtitle = @"阜通東大街6號";    [_mapView addAnnotation:pointAnnotation];//實現下列方法後能讓地圖上得圖釘彈出氣泡- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation{    if ([annotation isKindOfClass:[MAPointAnnotation class]])    {        static NSString *pointReuseIndetifier = @"pointReuseIndetifier";        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];        if (annotationView == nil)        {            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];        }        annotationView.canShowCallout= YES;       //設定氣泡可以彈出,預設為NO        annotationView.animatesDrop = YES;        //設定標註動畫顯示,預設為NO        annotationView.draggable = YES;        //設定標註可以拖動,預設為NO        annotationView.pinColor = MAPinAnnotationColorPurple;        return annotationView;            }    return nil;}用座標資訊判斷   你沒說想要的具體的效果  那我就給你說一種吧  假設你地圖上面有n個圖釘  實際上也就是n個pointAnnotation  你可以通過_mapView.annotations直接擷取到 這是個數組  在點擊圖釘的方法裡面- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{NSArray * array = [NSArray arrayWithArray:_mapView.annotations];    for (int i=0; i<array.count; i++)    {        if (view.annotation.coordinate.latitude ==((BMKPointAnnotation*)array[i]).coordinate.latitude)        {            //擷取到當前的圖釘  你可以執行一些操作        }        else        {            //對其餘的圖釘進行操作  我是刪除            //[_mapView removeAnnotation:array[i]];        }    }}


本文出自 “ZhuoKing” 部落格,請務必保留此出處http://9951038.blog.51cto.com/9941038/1764185

Ios 高德地圖 地圖上添加多個圖釘 怎麼在複用隊列中知道我單擊的是哪一個圖釘

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.