質問編集履歴
2
8つのデータを変更しました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
Button register_myHome = findViewById(R.id.register_my_home);
|
|
50
50
|
register_myHome.setOnClickListener(v -> {
|
|
51
51
|
|
|
52
|
-
//以下の8つ
|
|
53
52
|
home_latitude = findViewById(R.id.home_latitude);
|
|
54
53
|
write_latitude = findViewById(R.id.now_latitude);
|
|
55
54
|
String text1 = write_latitude.getText().toString();
|
|
@@ -59,7 +58,6 @@
|
|
|
59
58
|
write_longitude = findViewById(R.id.now_longitude);
|
|
60
59
|
String text2 = write_longitude.getText().toString();
|
|
61
60
|
home_longitude.setText(text2);
|
|
62
|
-
//以上
|
|
63
61
|
|
|
64
62
|
});
|
|
65
63
|
home_latitude = findViewById(R.id.home_latitude);
|
|
@@ -71,6 +69,7 @@
|
|
|
71
69
|
Button btn_distance_to_home = findViewById(R.id.btn_distance_to_home);
|
|
72
70
|
btn_distance_to_home.setOnClickListener(v -> {
|
|
73
71
|
|
|
72
|
+
//以下の8つ
|
|
74
73
|
String now_latitude2 = now_latitude.getText().toString();
|
|
75
74
|
String now_longitude2 = now_longitude.getText().toString();
|
|
76
75
|
double now_latitude3 = Double.parseDouble(now_latitude2);
|
|
@@ -80,6 +79,7 @@
|
|
|
80
79
|
String home_longitude2 = home_longitude.getText().toString();
|
|
81
80
|
double home_latitude3 = Double.parseDouble(home_latitude2);
|
|
82
81
|
double home_longitude3 = Double.parseDouble(home_longitude2);
|
|
82
|
+
//以上
|
|
83
83
|
|
|
84
84
|
float[] distance =
|
|
85
85
|
getDistance(now_latitude3, now_longitude3, home_latitude3, home_longitude3);
|
1
コードをアクティビティ全体にしました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -11,12 +11,66 @@
|
|
|
11
11
|
### 該当のソースコード
|
|
12
12
|
|
|
13
13
|
```ここに言語名を入力
|
|
14
|
+
|
|
15
|
+
public class DistanceActivity extends AppCompatActivity {
|
|
16
|
+
|
|
17
|
+
private FusedLocationProviderClient fusedLocationClient;
|
|
18
|
+
TextView home_latitude;
|
|
19
|
+
TextView write_latitude;
|
|
20
|
+
TextView home_longitude;
|
|
21
|
+
TextView write_longitude;
|
|
22
|
+
TextView set_distance;
|
|
23
|
+
EditText assumed_distance;
|
|
24
|
+
|
|
25
|
+
TextView now_latitude;
|
|
26
|
+
TextView now_longitude;
|
|
27
|
+
TextView num_distance_to_home;
|
|
28
|
+
|
|
29
|
+
String num_distance_to_home2;
|
|
30
|
+
double num_distance_to_home3;
|
|
31
|
+
String set_distance2;
|
|
32
|
+
double set_distance3;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@Override
|
|
36
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
37
|
+
super.onCreate(savedInstanceState);
|
|
38
|
+
setContentView(R.layout.activity_distance);
|
|
39
|
+
|
|
40
|
+
// LocationClientクラスのインスタンスを生成
|
|
41
|
+
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
|
42
|
+
|
|
43
|
+
// 位置情報取得開始
|
|
44
|
+
startUpdateLocation();
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
//こちらに以下の8つを置きたい。
|
|
48
|
+
|
|
49
|
+
Button register_myHome = findViewById(R.id.register_my_home);
|
|
50
|
+
register_myHome.setOnClickListener(v -> {
|
|
51
|
+
|
|
52
|
+
//以下の8つ
|
|
53
|
+
home_latitude = findViewById(R.id.home_latitude);
|
|
54
|
+
write_latitude = findViewById(R.id.now_latitude);
|
|
55
|
+
String text1 = write_latitude.getText().toString();
|
|
56
|
+
home_latitude.setText(text1);
|
|
57
|
+
|
|
58
|
+
home_longitude = findViewById(R.id.home_longitude);
|
|
59
|
+
write_longitude = findViewById(R.id.now_longitude);
|
|
60
|
+
String text2 = write_longitude.getText().toString();
|
|
61
|
+
home_longitude.setText(text2);
|
|
62
|
+
//以上
|
|
63
|
+
|
|
64
|
+
});
|
|
65
|
+
home_latitude = findViewById(R.id.home_latitude);
|
|
66
|
+
home_longitude = findViewById(R.id.home_longitude);
|
|
67
|
+
|
|
68
|
+
|
|
14
69
|
//ボタンを押すと、距離を算出してくれる仕組み
|
|
15
70
|
//distance[0]は2地点間の距離
|
|
16
71
|
Button btn_distance_to_home = findViewById(R.id.btn_distance_to_home);
|
|
17
72
|
btn_distance_to_home.setOnClickListener(v -> {
|
|
18
73
|
|
|
19
|
-
//ここから下の8つをリスナの外に出したい。
|
|
20
74
|
String now_latitude2 = now_latitude.getText().toString();
|
|
21
75
|
String now_longitude2 = now_longitude.getText().toString();
|
|
22
76
|
double now_latitude3 = Double.parseDouble(now_latitude2);
|
|
@@ -26,7 +80,6 @@
|
|
|
26
80
|
String home_longitude2 = home_longitude.getText().toString();
|
|
27
81
|
double home_latitude3 = Double.parseDouble(home_latitude2);
|
|
28
82
|
double home_longitude3 = Double.parseDouble(home_longitude2);
|
|
29
|
-
//以上8つ
|
|
30
83
|
|
|
31
84
|
float[] distance =
|
|
32
85
|
getDistance(now_latitude3, now_longitude3, home_latitude3, home_longitude3);
|
|
@@ -36,4 +89,23 @@
|
|
|
36
89
|
num_distance_to_home.setText(dis);
|
|
37
90
|
});
|
|
38
91
|
num_distance_to_home = findViewById(R.id.num_distance_to_home);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* 2点間の距離(メートル)、方位角(始点、終点)を取得
|
|
97
|
+
* ※配列で返す[距離、始点から見た方位角、終点から見た方位角]
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
public float[] getDistance(double x, double y, double x2, double y2) {
|
|
101
|
+
// 結果を格納するための配列を生成
|
|
102
|
+
float[] results = new float[3];
|
|
103
|
+
|
|
104
|
+
// 距離計算
|
|
105
|
+
Location.distanceBetween(x, y, x2, y2, results);
|
|
106
|
+
|
|
107
|
+
return results;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
39
111
|
```
|