免費開源的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;
                                                              }
                                                              

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


                                                              97人人超人人超碰超中文|免看一级a一级久久|国产熟睡乱子伦午夜|卡通动漫久久五月天 亚洲国产免费综合网日韩 亚洲日本中文字幕乱码在线 伊人久久大香线蕉av蜜芽 久久综合一香蕉老鬼色一个 91 中文字幕 国产 日韩 全彩3d啪啪无码本子全彩千乐网 亚洲中文字幕无码永久 三级三级久久三级 国产日产在线不卡省流观看