teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

ブラウザのページソース結果追加

2021/11/25 11:33

投稿

hahaha44444
hahaha44444

スコア0

title CHANGED
File without changes
body CHANGED
@@ -127,4 +127,90 @@
127
127
  ### 補足情報(FW/ツールのバージョンなど)
128
128
  xampp contorol panel v3.2.4
129
129
 
130
- ここにより詳細な情報を記載してください。
130
+ ここにより詳細な情報を記載してください。
131
+
132
+ ###ブラウザのページのソース表示結果
133
+ ```
134
+ <!DOCTYPE html>
135
+ <html lang="ja">
136
+ <head>
137
+ <meta charset="utf-8">
138
+ <title>距離計算</title>
139
+ <style></style>
140
+ </head>
141
+ <body>
142
+ 場所:honnatugi-staton<br>緯度:35.4349408<br>経度:139.339615<br>
143
+ <script>
144
+ //ユーザーの現在の位置情報を取得
145
+ navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
146
+
147
+ // ユーザーの現在の位置情報を取得
148
+ function successCallback(position) {
149
+ const latitude1 = position.coords.latitude
150
+ const longitude1 = position.coords.longitude
151
+ let coord = <br />
152
+ <b>Notice</b>: Undefined variable: json_row in <b>C:\xampp\htdocs\セミナー\showtable.php</b> on line <b>38</b><br />
153
+
154
+ console.log(coord["latitude"]);
155
+ console.log(coord["longitude"]);
156
+ //const latitude2 = 35.4349408
157
+ //const longitude2 = 139.339615
158
+
159
+ const latitude3 = 35.480947
160
+ const longitude3 = 139.321024
161
+ var gl_text = "緯度:" + latitude1 + "<br>";
162
+ gl_text += "経度:" + longitude1 + "<br>";
163
+ const dis1 = distance(latitude1,longitude1,coord["latitude"],coord["longitude"])
164
+ const dis2 = distance(latitude1,longitude1,latitude3,longitude3)
165
+ gl_text += "駅までの距離 :" +dis1+"<br>"
166
+ gl_text += "運動公園までの距離 :" +dis2+"<br><br>"
167
+ if (compare(dis1,dis2)==1){
168
+ gl_text += "運動公園のほうが近いです<br>"
169
+ }
170
+ else {
171
+ gl_text += "駅のほうが近いです<br>"
172
+ }
173
+ document.getElementById("show_result").innerHTML = gl_text;
174
+
175
+ }
176
+
177
+ function compare (dis1,dis2){
178
+ if ((dis1-dis2)>0){
179
+ return 1
180
+ }
181
+ else
182
+ return 2
183
+ }
184
+ //2点間の距離計算
185
+ function distance(lat1,lng1,lat2,lng2){
186
+ const R = Math.PI / 180
187
+ lat1*=R;
188
+ lng1*=R;
189
+ lat2*=R;
190
+ lng2*=R;
191
+ return 6371 * Math.acos(Math.cos(lat1) * Math.cos(lat2) * Math.cos(lng2 - lng1) + Math.sin(lat1) * Math.sin(lat2));
192
+ }
193
+
194
+ // 位置情報が取得できない場合
195
+ function errorCallback(error) {
196
+ var err_msg = "";
197
+ switch(error.code)
198
+ {
199
+ case 1:
200
+ err_msg = "位置情報の利用が許可されていません";
201
+ break;
202
+ case 2:
203
+ err_msg = "デバイスの位置が判定できません";
204
+ break;
205
+ case 3:
206
+ err_msg = "タイムアウトしました";
207
+ break;
208
+ }
209
+ document.getElementById("show_result").innerHTML = err_msg;
210
+ }
211
+ </script>
212
+ <p>あなたの現在位置</p>
213
+ <div id="show_result"></div>
214
+ </body>
215
+ </html>
216
+ ```

1

codeの乗せ方

2021/11/25 11:33

投稿

hahaha44444
hahaha44444

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,6 @@
1
+ ```ここに言語を入力
2
+ コード
1
- ### 前提・実現したいこと
3
+ ```### 前提・実現したいこと
2
4
  phpとjavascriptを用いて現在の位置情報を「geolocationapi」から取得し
3
5
  dbに登録した座標(緯度経度)を用いて距離を算出し一番近いものを表示するというプログラムを作成しています
4
6
 
@@ -14,10 +16,7 @@
14
16
  ```
15
17
 
16
18
  ### 該当のソースコード
17
-
18
- ```php,javascript
19
- ```
19
+ ```php
20
-
21
20
  <!DOCTYPE html>
22
21
  <html lang="ja">
23
22
  <head>
@@ -120,6 +119,7 @@
120
119
  <div id="show_result"></div>
121
120
  </body>
122
121
  </html>
122
+ ```
123
123
  ### 試したこと
124
124
 
125
125
  json_encode