2017-12-21 4 views
0

나는 승객과 운전자를위한 많은 주석이있는 Uber 클론을 만들고자합니다. 현재 표시된 맵 영역에 속한 주석 만로드하여 표시하므로 모든 주석이 맵뷰에 추가되지 않고 많은 메모리를 소비하지 않습니다.신속한 신청서에 많은 주석이 있습니다. 현재 보이는지도 영역의 주석 만 표시하려면 어떻게해야합니까?

운전자와 탑승자의 두 가지 유형의 주석이 있습니다. 주석이 달린 이미지가 다릅니다. 여기

내가 그것을하려고 방법입니다

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
     if let annotation = annotation as? DriverAnnotation { 
      guard let dequeuedDriverAnnotation = mapView.dequeueReusableAnnotationView(withIdentifier: "driver") else { 
       let driverAnnotation = MKAnnotationView(annotation: annotation, reuseIdentifier: "driver") 
        driverAnnotation.image = UIImage(named: "driverAnnotation") 
        return driverAnnotation 
       } 
       dequeuedDriverAnnotation.annotation = annotation 
       return dequeuedDriverAnnotation 
      } else if let annotation = annotation as? PassengerAnnotation { 
       guard let dequeuedPassengerAnnotation = mapView.dequeueReusableAnnotationView(withIdentifier: "passenger") else { 
        let passengerAnnotation = MKAnnotationView(annotation: annotation, reuseIdentifier: "passenger") 
        passengerAnnotation.image = UIImage(named: "currentLocationAnnotation") 
        return passengerAnnotation 
       } 
       dequeuedPassengerAnnotation.annotation = annotation 
       return dequeuedPassengerAnnotation 
      } 
      return nil 
    } 
} 
+0

정말 귀하의 질문에 대답하지,하지만 일반적으로이 현재 위치를 수락 할 백엔드 API에 의해 해결 :

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { if !visibleMapRegion(annotation) { return nil } ... 

하면이 기능은 또한 참조 정의하려면 및 커버 반경. 따라서 db 데이터와 비교하기 위해 서버에서 계산을 더 쉽게 수행 할 수 있습니다. – xmhafiz

답변

관련 문제