I am using firebase to store a users location into the database, and I am getting returned this, I am not sure if it is an error or just something was interpreted wrong:
[]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"]\\\\\\\\\\\\\\\"]\\\\\\\"]\\\"]\"]"]
This above but like 10x longer
Full Code:
import SwiftUI
import MapKit
import Firebase
import CoreLocationUI
struct MapView: View {
@StateObject private var viewModel = ContentViewModel()
@State var address = ""
@State var addresses:[String] = []
@State var realLat:[String] = []
@State var realLong:[String] = []
var body: some View {
NavigationView {
VStack {
List(0..<realLat.count, id: \.self) {i in Text(realLat[i]) }
List(0..<realLong.count, id: \.self) {i in Text(realLong[i]) }
}
.onAppear(perform: {
downloadLatServerData()
downloadLongServerData()
})
}
}
func downloadLatServerData() {
//address = "Tokyo" // <--- here for testing
//addresses.append(address) // <--- here for testing
let db = Firestore.firestore()
db.collection("UserInfo").addSnapshotListener {(snap, err) in
if err != nil{
print("\(String(describing: err))")
return
}
for i in snap!.documentChanges {
let documentId = i.document.documentID
if let latCoordinate = i.document.get("lat") as? String {
DispatchQueue.main.async {
realLat.append(latCoordinate)
print("\(realLat)")
}
}
}
}
}
func downloadLongServerData() {
//address = "Tokyo" // <--- here for testing
//addresses.append(address) // <--- here for testing
let db = Firestore.firestore()
db.collection("UserInfo").addSnapshotListener {(snap, err) in
if err != nil{
print("\(String(describing: err))")
return
}
for i in snap!.documentChanges {
let documentId = i.document.documentID
if let longCoordniate = i.document.get("long") as? String {
DispatchQueue.main.async {
realLong.append(longCoordniate)
print("\(realLong)")
}
}
}
}
}
}
Sample Numbers:
Lat: -9128653.12 Long: -917532
Did those numbers 4 times, for 4 different users.
CodePudding user response:
try this:
use realLat.append(latCoordinate)
not realLat.append("\(realLat)")
and similarly for realLong
.
use realLong.append(longCoordniate)
not realLong.append("\(realLong)")