質問編集履歴

2

修正の修正

2019/10/17 07:22

投稿

old_dog
old_dog

スコア51

test CHANGED
File without changes
test CHANGED
@@ -57,57 +57,3 @@
57
57
  } } }); } }
58
58
 
59
59
  ```
60
-
61
- R011017
62
-
63
- 下記修正コードでpermissionの確認をしています。事前にディバイス側の位置情報の取得を認める設定をして動作確認しています。
64
-
65
- ```MainActivity
66
-
67
- public class MainActivity extends AppCompatActivity{
68
-
69
-
70
-
71
- FusedLocationProviderClient fusedLocationClient;
72
-
73
- TextView textView;
74
-
75
-
76
-
77
- @Override
78
-
79
- protected void onCreate(Bundle savedInstanceState) {
80
-
81
- super.onCreate(savedInstanceState);
82
-
83
- setContentView(R.layout.activity_main);
84
-
85
-
86
-
87
- textView = findViewById(R.id.textView);
88
-
89
- fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
90
-
91
- if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
92
-
93
- fusedLocationClient.getLastLocation().addOnSuccessListener(this,new OnSuccessListener<Location>(){
94
-
95
- @Override
96
-
97
- public void onSuccess(Location location) {
98
-
99
- if(location != null){
100
-
101
- String latitude = String.valueOf(location.getLatitude());
102
-
103
- textView.setText(latitude);
104
-
105
- }else{
106
-
107
- textView.setText("false");
108
-
109
- } } } }); } }
110
-
111
- ```
112
-
113
- デバックでは、pulic void onSuccess(Lication location)は、location == null となります。

1

変更コードを掲載

2019/10/17 07:22

投稿

old_dog
old_dog

スコア51

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
19
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
20
20
 
21
21
  </manifest>
22
22
 
@@ -25,8 +25,6 @@
25
25
 
26
26
 
27
27
  ```MainActivity
28
-
29
-
30
28
 
31
29
  public class MainActivity extends AppCompatActivity {
32
30
 
@@ -56,14 +54,60 @@
56
54
 
57
55
  Log.d("MSG","onSuccess");
58
56
 
59
- }
60
-
61
- }
62
-
63
- });
57
+ } } }); } }
64
-
65
- }
66
-
67
- }
68
58
 
69
59
  ```
60
+
61
+ R011017
62
+
63
+ 下記修正コードでpermissionの確認をしています。事前にディバイス側の位置情報の取得を認める設定をして動作確認しています。
64
+
65
+ ```MainActivity
66
+
67
+ public class MainActivity extends AppCompatActivity{
68
+
69
+
70
+
71
+ FusedLocationProviderClient fusedLocationClient;
72
+
73
+ TextView textView;
74
+
75
+
76
+
77
+ @Override
78
+
79
+ protected void onCreate(Bundle savedInstanceState) {
80
+
81
+ super.onCreate(savedInstanceState);
82
+
83
+ setContentView(R.layout.activity_main);
84
+
85
+
86
+
87
+ textView = findViewById(R.id.textView);
88
+
89
+ fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
90
+
91
+ if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
92
+
93
+ fusedLocationClient.getLastLocation().addOnSuccessListener(this,new OnSuccessListener<Location>(){
94
+
95
+ @Override
96
+
97
+ public void onSuccess(Location location) {
98
+
99
+ if(location != null){
100
+
101
+ String latitude = String.valueOf(location.getLatitude());
102
+
103
+ textView.setText(latitude);
104
+
105
+ }else{
106
+
107
+ textView.setText("false");
108
+
109
+ } } } }); } }
110
+
111
+ ```
112
+
113
+ デバックでは、pulic void onSuccess(Lication location)は、location == null となります。