質問編集履歴

1

テスト作成したコードの追記

2018/07/19 04:06

投稿

YashaWedyue
YashaWedyue

スコア830

test CHANGED
File without changes
test CHANGED
@@ -27,3 +27,59 @@
27
27
 
28
28
 
29
29
  拙い質問で申し訳ございませんが、ご回答のほどよろしくお願いいたします。
30
+
31
+
32
+
33
+ **// 追記**
34
+
35
+ テスト用に作成したコードを追記します。
36
+
37
+ ```JavaScript
38
+
39
+ $(function() {
40
+
41
+ let locationObj = navigator.geolocation.watchPosition(
42
+
43
+ function(position) {
44
+
45
+ let latitude = position.coords.latitude;
46
+
47
+ let longitude = position.coords.longitude;
48
+
49
+ let accuracy = position.coords.accuracy;
50
+
51
+
52
+
53
+ // DBに保存
54
+
55
+ $.post("post.php", { // SQLを発行するだけのPHP
56
+
57
+ id: 1, // テスト用データ
58
+
59
+ latitude : latitude,
60
+
61
+ longitude: longitude
62
+
63
+ });
64
+
65
+
66
+
67
+ // ログ出力
68
+
69
+ $("#log").append(latitude+", "+longitude+", "+accuracy+"<br>");
70
+
71
+ },
72
+
73
+ function() {
74
+
75
+ alert("位置情報を取得できません!");
76
+
77
+ navigator.geolocation.clearWatch(locationObj);
78
+
79
+ }
80
+
81
+ );
82
+
83
+ });
84
+
85
+ ```