質問編集履歴
2
8つのデータを変更しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -100,8 +100,6 @@
|
|
100
100
|
|
101
101
|
|
102
102
|
|
103
|
-
//以下の8つ
|
104
|
-
|
105
103
|
home_latitude = findViewById(R.id.home_latitude);
|
106
104
|
|
107
105
|
write_latitude = findViewById(R.id.now_latitude);
|
@@ -120,8 +118,6 @@
|
|
120
118
|
|
121
119
|
home_longitude.setText(text2);
|
122
120
|
|
123
|
-
//以上
|
124
|
-
|
125
121
|
|
126
122
|
|
127
123
|
});
|
@@ -144,6 +140,8 @@
|
|
144
140
|
|
145
141
|
|
146
142
|
|
143
|
+
//以下の8つ
|
144
|
+
|
147
145
|
String now_latitude2 = now_latitude.getText().toString();
|
148
146
|
|
149
147
|
String now_longitude2 = now_longitude.getText().toString();
|
@@ -162,6 +160,8 @@
|
|
162
160
|
|
163
161
|
double home_longitude3 = Double.parseDouble(home_longitude2);
|
164
162
|
|
163
|
+
//以上
|
164
|
+
|
165
165
|
|
166
166
|
|
167
167
|
float[] distance =
|
1
コードをアクティビティ全体にしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,6 +24,116 @@
|
|
24
24
|
|
25
25
|
```ここに言語名を入力
|
26
26
|
|
27
|
+
|
28
|
+
|
29
|
+
public class DistanceActivity extends AppCompatActivity {
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
private FusedLocationProviderClient fusedLocationClient;
|
34
|
+
|
35
|
+
TextView home_latitude;
|
36
|
+
|
37
|
+
TextView write_latitude;
|
38
|
+
|
39
|
+
TextView home_longitude;
|
40
|
+
|
41
|
+
TextView write_longitude;
|
42
|
+
|
43
|
+
TextView set_distance;
|
44
|
+
|
45
|
+
EditText assumed_distance;
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
TextView now_latitude;
|
50
|
+
|
51
|
+
TextView now_longitude;
|
52
|
+
|
53
|
+
TextView num_distance_to_home;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
String num_distance_to_home2;
|
58
|
+
|
59
|
+
double num_distance_to_home3;
|
60
|
+
|
61
|
+
String set_distance2;
|
62
|
+
|
63
|
+
double set_distance3;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
@Override
|
70
|
+
|
71
|
+
protected void onCreate(Bundle savedInstanceState) {
|
72
|
+
|
73
|
+
super.onCreate(savedInstanceState);
|
74
|
+
|
75
|
+
setContentView(R.layout.activity_distance);
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
// LocationClientクラスのインスタンスを生成
|
80
|
+
|
81
|
+
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
// 位置情報取得開始
|
86
|
+
|
87
|
+
startUpdateLocation();
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
//こちらに以下の8つを置きたい。
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
Button register_myHome = findViewById(R.id.register_my_home);
|
98
|
+
|
99
|
+
register_myHome.setOnClickListener(v -> {
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
//以下の8つ
|
104
|
+
|
105
|
+
home_latitude = findViewById(R.id.home_latitude);
|
106
|
+
|
107
|
+
write_latitude = findViewById(R.id.now_latitude);
|
108
|
+
|
109
|
+
String text1 = write_latitude.getText().toString();
|
110
|
+
|
111
|
+
home_latitude.setText(text1);
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
home_longitude = findViewById(R.id.home_longitude);
|
116
|
+
|
117
|
+
write_longitude = findViewById(R.id.now_longitude);
|
118
|
+
|
119
|
+
String text2 = write_longitude.getText().toString();
|
120
|
+
|
121
|
+
home_longitude.setText(text2);
|
122
|
+
|
123
|
+
//以上
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
});
|
128
|
+
|
129
|
+
home_latitude = findViewById(R.id.home_latitude);
|
130
|
+
|
131
|
+
home_longitude = findViewById(R.id.home_longitude);
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
27
137
|
//ボタンを押すと、距離を算出してくれる仕組み
|
28
138
|
|
29
139
|
//distance[0]は2地点間の距離
|
@@ -34,8 +144,6 @@
|
|
34
144
|
|
35
145
|
|
36
146
|
|
37
|
-
//ここから下の8つをリスナの外に出したい。
|
38
|
-
|
39
147
|
String now_latitude2 = now_latitude.getText().toString();
|
40
148
|
|
41
149
|
String now_longitude2 = now_longitude.getText().toString();
|
@@ -54,8 +162,6 @@
|
|
54
162
|
|
55
163
|
double home_longitude3 = Double.parseDouble(home_longitude2);
|
56
164
|
|
57
|
-
//以上8つ
|
58
|
-
|
59
165
|
|
60
166
|
|
61
167
|
float[] distance =
|
@@ -74,4 +180,42 @@
|
|
74
180
|
|
75
181
|
num_distance_to_home = findViewById(R.id.num_distance_to_home);
|
76
182
|
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
/*
|
190
|
+
|
191
|
+
* 2点間の距離(メートル)、方位角(始点、終点)を取得
|
192
|
+
|
193
|
+
* ※配列で返す[距離、始点から見た方位角、終点から見た方位角]
|
194
|
+
|
195
|
+
*/
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
public float[] getDistance(double x, double y, double x2, double y2) {
|
200
|
+
|
201
|
+
// 結果を格納するための配列を生成
|
202
|
+
|
203
|
+
float[] results = new float[3];
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
// 距離計算
|
208
|
+
|
209
|
+
Location.distanceBetween(x, y, x2, y2, results);
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
return results;
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
}
|
220
|
+
|
77
221
|
```
|