| | |
| | | mapView.frame = CGRect(origin: .zero, size: view_container.size) |
| | | |
| | | for (index,v) in models.enumerated(){ |
| | | let point = MAPointAnnotation() |
| | | let point = CustomPointAnnotation() |
| | | point.coordinate = CLLocationCoordinate2D(latitude: v.latitude, longitude:v.longitude) |
| | | point.title = v.storeName |
| | | point.title = v.storeAddr |
| | | point.index = index |
| | | v.index = index |
| | | v.annotation = point |
| | | } |
| | | |
| | | let points = models.map({$0.annotation}) as! [MAPointAnnotation] |
| | | let points = models.map({$0.annotation}) as! [CustomPointAnnotation] |
| | | mapView.addAnnotations(points) |
| | | mapView.showAnnotations(points, animated: true) |
| | | mapView.selectAnnotation(points.first!, animated: true) |
| | |
| | | extension SearchVC:MAMapViewDelegate{ |
| | | |
| | | func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { |
| | | if annotation is MAPointAnnotation{ |
| | | var pointView = mapView.dequeueReusableAnnotationView(withIdentifier: "point") |
| | | if annotation is CustomPointAnnotation{ |
| | | var pointView = mapView.dequeueReusableAnnotationView(withIdentifier: "point") as? CustomPointAnnotationView |
| | | if pointView == nil{ |
| | | pointView = MAAnnotationView(annotation: annotation, reuseIdentifier: "point") |
| | | pointView = CustomPointAnnotationView(annotation: annotation, reuseIdentifier: "point") |
| | | } |
| | | pointView?.canShowCallout = true |
| | | pointView?.label.text = "\((annotation as! CustomPointAnnotation).index + 1)" |
| | | pointView?.image = UIImage(named: "icon_point")?.withTintColor(UIColor(hexStr: "#f54444")) |
| | | return pointView |
| | | } |