Skip to content

Commit

Permalink
add lat lon factor (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
mltbnz committed Jun 5, 2023
1 parent 48d59ab commit 9eedb56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ public struct SendLocationPostBody: Encodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.device, forKey: .device)
try container.encodeIfPresent(self.location?.coordinate.latitude, forKey: .latitude)
try container.encodeIfPresent(self.location?.coordinate.longitude, forKey: .longitude)
if let location {
try container.encodeIfPresent(
location.coordinate.latitude * 1_000_000,
forKey: .latitude
)
try container.encodeIfPresent(
location.coordinate.longitude * 1_000_000,
forKey: .longitude
)
}
}
}
8 changes: 4 additions & 4 deletions CriticalMapsKit/Sources/SharedModels/Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ extension Location: Codable {

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let latitude = try container.decode(Double.self, forKey: .latitude) / 1000000
let longitude = try container.decode(Double.self, forKey: .longitude) / 1000000
let latitude = try container.decode(Double.self, forKey: .latitude) / 1_000_000
let longitude = try container.decode(Double.self, forKey: .longitude) / 1_000_000
coordinate = Coordinate(latitude: latitude, longitude: longitude)
try timestamp = container.decode(Double.self, forKey: .timestamp)
try name = container.decodeIfPresent(String.self, forKey: .name)
Expand All @@ -49,8 +49,8 @@ extension Location: Codable {

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(coordinate.longitude * 1000000, forKey: .longitude)
try container.encode(coordinate.latitude * 1000000, forKey: .latitude)
try container.encode(coordinate.longitude * 1_000_000, forKey: .longitude)
try container.encode(coordinate.latitude * 1_000_000, forKey: .latitude)
try container.encode(timestamp, forKey: .timestamp)
try container.encodeIfPresent(color, forKey: .color)
try container.encodeIfPresent(name, forKey: .name)
Expand Down

0 comments on commit 9eedb56

Please sign in to comment.