免費開源的iOS開發學習平臺

                                                高德地圖SDK:4-繪制地圖標注

                                                同MapKit框架類似,使用高德地圖SDK也可以在地圖上添加標注。標注可以精確表示用戶需要展示的位置信息,高德地圖SDK提供的標注功能允許用戶自定義圖標和信息窗,同時提供了標注的點擊、拖動事件的回調。高德地圖SDK提供的地圖標注為MAAnnotation類,不同的標記可以根據圖標和改變信息窗的樣式和內容加以區分。

                                                添加默認樣式點標記

                                                高德地圖SDK提供的大頭針標注MAPinAnnotationView,通過它可以設置大頭針顏色、是否顯示動畫、是否支持長按后拖拽大頭針改變坐標等。在地圖上添加大頭針標注的步驟如下:

                                                • 修改ViewController.m文件,在viewDidAppear方法中添加如下所示代碼添加標注數據對象
                                                -(void)viewDidAppear:(BOOL)animated{
                                                    [super viewDidAppear:animated];
                                                    //添加大頭針
                                                    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
                                                    pointAnnotation.coordinate = CLLocationCoordinate2DMake(32.03522, 118.74237);
                                                    pointAnnotation.title = @"侵華日軍南京大屠殺遇難同胞紀念館";
                                                    pointAnnotation.subtitle = @"水西門大街418號";
                                                    [self.mapView addAnnotation:pointAnnotation];
                                                    self.mapView.centerCoordinate = pointAnnotation.coordinate;
                                                }
                                                
                                                • 實現MAMapViewDelegate協議中的 mapView:viewForAnnotation:回調函數,設置標注樣式。
                                                - (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation
                                                {
                                                    if ([annotation isKindOfClass:[MAPointAnnotation class]])
                                                    {
                                                        static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
                                                        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
                                                        if (annotationView == nil)
                                                        {
                                                            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
                                                        }
                                                        annotationView.canShowCallout= YES;       //設置氣泡可以彈出,默認為NO
                                                        annotationView.animatesDrop = YES;        //設置標注動畫顯示,默認為NO
                                                        annotationView.draggable = YES;        //設置標注可以拖動,默認為NO
                                                        annotationView.pinColor = MAPinAnnotationColorPurple;
                                                        return annotationView;
                                                    }
                                                    return nil;
                                                }
                                                

                                                運行后,可以在地圖上展示地圖標注。


                                                欧美超级精品一级A片|欧美一级黄色视频|国产精品自在在线午夜免费|4444亚洲人成无码网在线观看|亚洲ⅴa曰本va欧美va视频