NCViewerImageDetailView.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // NCViewerImageDetailView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 31/10/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. import Foundation
  9. import MapKit
  10. class NCViewerImageDetailView: UIView {
  11. @IBOutlet weak var mapView: MKMapView!
  12. @IBOutlet weak var locationButton: UIButton!
  13. var annotation = MKPointAnnotation()
  14. var latitude: Double = 0
  15. var longitude: Double = 0
  16. override func awakeFromNib() {
  17. super.awakeFromNib()
  18. mapView.layer.cornerRadius = 6
  19. }
  20. func updateExifLocal(metadata: tableMetadata) {
  21. if metadata.typeFile == k_metadataTypeFile_image {
  22. CCExifGeo.sharedInstance()?.setExif(metadata)
  23. }
  24. if let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
  25. latitude = Double(localFile.exifLatitude) ?? 0
  26. longitude = Double(localFile.exifLongitude) ?? 0
  27. if latitude > 0 && longitude > 0 {
  28. annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
  29. mapView.addAnnotation(annotation)
  30. mapView.setRegion(MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
  31. if let location = NCManageDatabase.sharedInstance.getLocationFromGeoLatitude(localFile.exifLatitude, longitude: localFile.exifLongitude) {
  32. locationButton.setTitle(location, for: .normal)
  33. }
  34. }
  35. }
  36. }
  37. }