52 lines
1.5 KiB
Swift
52 lines
1.5 KiB
Swift
//
|
|
// VehicleEventDto.swift
|
|
// AutoCatCore
|
|
//
|
|
// Created by Selim Mustafaev on 12.06.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public struct VehicleEventDto: Codable, Sendable, Equatable, Hashable {
|
|
|
|
public var id: String = UUID().uuidString
|
|
public var date: TimeInterval = Date().timeIntervalSince1970
|
|
public var latitude: Double = 0
|
|
public var longitude: Double = 0
|
|
public var address: String? = nil
|
|
public var addedBy: String? = nil
|
|
public var number: String?
|
|
|
|
public init(lat: Double, lon: Double, addedBy: String?) {
|
|
self.latitude = lat
|
|
self.longitude = lon
|
|
self.addedBy = addedBy
|
|
}
|
|
|
|
public func getMapLink() -> URL? {
|
|
var urlString = "http://maps.apple.com/?sll=\(self.latitude),\(self.longitude)"
|
|
if let address = self.address?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
|
|
urlString = urlString + "&address=" + address
|
|
}
|
|
return URL(string: urlString)
|
|
}
|
|
|
|
public func getLocationString() -> String {
|
|
let coordinates = "Lat: \(self.latitude), Lon: \(self.longitude)"
|
|
if let addressString = self.address {
|
|
return "\(addressString) (\(coordinates)"
|
|
} else {
|
|
return coordinates
|
|
}
|
|
}
|
|
|
|
public var location: String {
|
|
if let address {
|
|
return address
|
|
} else {
|
|
return "\(latitude), \(longitude)"
|
|
}
|
|
}
|
|
}
|