回答編集履歴

1

記載内容の修正

2019/11/29 06:21

投稿

popai306
popai306

スコア157

test CHANGED
@@ -1,15 +1,43 @@
1
- 単純に逆はなくて
1
+ これ取れませんかね
2
2
 
3
3
  ```
4
4
 
5
-
5
+ @IBAction func othersLocation(_ sender: Any)
6
6
 
7
+ {
8
+
9
+ //Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional valueのエラー
10
+
11
+ ref.child("users").child("userCoordinate").observeSingleEvent(of: .value, with: { (snapshot) in
12
+
13
+ let value = snapshot.value as? NSDictionary
14
+
7
- ref.child("userLatitude").child(user!)
15
+ let otherUserLatitude = value?["userLatitude"] as? String
16
+
17
+ print("ユーザー緯度:", otherUserLatitude)
18
+
19
+ })
20
+
21
+ }
22
+
23
+ ```
8
24
 
9
25
 
10
26
 
11
- 正?
12
-
13
- ref.child(user!).child("userLatitude")
27
+ あるべきはsetValue時に
14
28
 
15
29
  ```
30
+
31
+ let userCoordinate = ["userLatitude": latitude.text]
32
+
33
+ ref.child("users").child(user!).setValue(["userCoordinate": userCoordinate])
34
+
35
+ ```
36
+
37
+ 取得するときは
38
+
39
+ ```
40
+
41
+ ref.child("users").child(user!).child("userCoordinate")...
42
+
43
+ ```