使用多个图钉在地图中定位用户的位置



我需要使用自定义注释查看用户位置,然后在用户附近添加了更多类型的注释(例如,古迹,餐厅电影院...)。如果我在此方法中编写代码,将显示用户的位置。

- (void) locationManager:(CLLocationManager *) manager
 didUpdateToLocation:(CLLocation *) newLocation
        fromLocation:(CLLocation *) oldLocation {
    //......
   MyAnnotation *annotationUser = [[MyAnnotation alloc]initWithCoordinates:self.coordinate  title:@"YOU ARE HERE" subTitle:@"via Giorgio Giulini 2"];
   [self.mapView addAnnotation:self.annotationUser];

}

如果我添加方法

 - (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
 {
      //.....
  }

为了创建其他注释,不再显示用户的位置。为什么?

尝试此

    - (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
 {
    if ([annotation isKindOfClass:[MyAnnotation class]]) {
        return nil;
    } else {
        //.....
    }

  }

最新更新