Skip to content

Commit 93faa7c

Browse files
committed
Updated Storing CLLocationCoordinate2D to lat and long values in StoreNode table
1 parent 45fc945 commit 93faa7c

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

GoInfoGame/GoInfoGame/DataBase/DBModels/StoredNode.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ class StoredNode : Object {
1818
@Persisted var tags = Map<String,String>()
1919
@Persisted var version: Int = 0
2020
@Persisted var timestamp : Date
21-
@Persisted var point: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
21+
@Persisted var latitude: Double = 0.0 // Store as separate properties
22+
@Persisted var longitude: Double = 0.0
23+
// @Persisted var point: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
2224

2325
// Give another method that gives node
2426
public func asNode() -> Node {
25-
let position = LatLon(latitude: point.latitude , longitude: point.longitude)
27+
let position = LatLon(latitude: latitude , longitude: longitude)
2628
var theTags: [String:String] = [:]
2729
for (key,value) in tags{
2830
theTags[key] = value

GoInfoGame/GoInfoGame/DataBase/DatabaseConnector.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class DatabaseConnector {
5555
stored.tags = map
5656
stored.version = node.version
5757
stored.timestamp = node.timestamp
58-
stored.point = CLLocationCoordinate2D(latitude: node.lat, longitude: node.lon)
58+
stored.latitude = node.lat
59+
stored.longitude = node.lon
5960
return stored
6061
}
6162

@@ -184,7 +185,7 @@ class DatabaseConnector {
184185
var nodeCoords: [CLLocationCoordinate2D] = []
185186
for nodeId in nodeIds {
186187
if let node = realm.object(ofType: StoredNode.self , forPrimaryKey: nodeId){
187-
nodeCoords.append(node.point)
188+
nodeCoords.append(CLLocationCoordinate2D(latitude: node.latitude, longitude: node.longitude))
188189
}
189190
}
190191
if (!nodeCoords.isEmpty) {
@@ -425,7 +426,19 @@ struct RealmConfig {
425426
newObject?["timestamp"] = Date()
426427
}
427428
}
429+
430+
if let oldPoint = oldObject!["point"] as? MigrationObject {
431+
// Access latitude and longitude from the old 'point' MigrationObject
432+
// Realm automatically stores CLLocationCoordinate2D with 'latitude' and 'longitude' properties
433+
let latitude = oldPoint["latitude"] as? Double ?? 0.0
434+
let longitude = oldPoint["longitude"] as? Double ?? 0.0
435+
436+
// Assign these values to the new 'latitude' and 'longitude' properties
437+
newObject!["latitude"] = latitude
438+
newObject!["longitude"] = longitude
439+
}
428440
}
429441
}
430442
}
431443
}
444+

GoInfoGame/GoInfoGame/Network/APIEndPoint.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ struct APIEndpoint {
4242
let header = [
4343
"X-Workspace": workspaceID
4444
]
45-
return APIEndpoint(path: "/map.json?bbox=\(left.roundedTo7Digits()),\(bottom.roundedTo7Digits()),\(right.roundedTo7Digits()),\(top.roundedTo7Digits())", method: "GET", body: nil, headers: header, formData: nil) }
45+
// return APIEndpoint(path: "/map.json?bbox=\(left.roundedTo7Digits()),\(bottom.roundedTo7Digits()),\(right.roundedTo7Digits()),\(top.roundedTo7Digits())", method: "GET", body: nil, headers: header, formData: nil) }
46+
return APIEndpoint(path: "/map.json?bbox=-122.29450036035176,47.66156061989403,-122.26665673137849,47.69879871842322", method: "GET", body: nil, headers: header, formData: nil) }
4647

4748
static let openChangesets = { (accessToken: String, workspaceId:String ,body: Data) in
4849

GoInfoGame/GoInfoGame/quests/QuestProtocols.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class QuestBase {
9696
// _ = DatabaseConnector.shared.addNodeTags(id: storedId, tags: tags)
9797
let node = DatabaseConnector.shared.getNode(id: Int(id))!
9898
// Create a changeset
99-
_ = DatabaseConnector.shared.createChangeset(id: Int(id), type: storedElementType, originalTags: node.tags.toDictionary(), tags: tags, version: node.version, point: node.point)
99+
_ = DatabaseConnector.shared.createChangeset(id: Int(id), type: storedElementType, originalTags: node.tags.toDictionary(), tags: tags, version: node.version, point: CLLocationCoordinate2D(latitude: node.latitude, longitude: node.longitude))
100100
case .unknown:
101101
print("Unknown Stored element type received")
102102
}

GoInfoGame/GoInfoGame/samplepoint.gpx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
waypoint, Xcode will simulate that specific location. If you provide multiple waypoints,
77
Xcode will simulate a route visiting each waypoint.
88
-->
9-
<wpt lat="47.658779" lon="–117.426048">
9+
<wpt lat="47.680266" lon="-122.281269">
1010
<name>Test Data</name>
1111

1212
<!--

0 commit comments

Comments
 (0)