質問編集履歴
2
修正の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -27,31 +27,4 @@
|
|
27
27
|
if(location != null){
|
28
28
|
Log.d("MSG","onSuccess");
|
29
29
|
} } }); } }
|
30
|
-
```
|
30
|
+
```
|
31
|
-
R011017
|
32
|
-
下記修正コードでpermissionの確認をしています。事前にディバイス側の位置情報の取得を認める設定をして動作確認しています。
|
33
|
-
```MainActivity
|
34
|
-
public class MainActivity extends AppCompatActivity{
|
35
|
-
|
36
|
-
FusedLocationProviderClient fusedLocationClient;
|
37
|
-
TextView textView;
|
38
|
-
|
39
|
-
@Override
|
40
|
-
protected void onCreate(Bundle savedInstanceState) {
|
41
|
-
super.onCreate(savedInstanceState);
|
42
|
-
setContentView(R.layout.activity_main);
|
43
|
-
|
44
|
-
textView = findViewById(R.id.textView);
|
45
|
-
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
46
|
-
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
|
47
|
-
fusedLocationClient.getLastLocation().addOnSuccessListener(this,new OnSuccessListener<Location>(){
|
48
|
-
@Override
|
49
|
-
public void onSuccess(Location location) {
|
50
|
-
if(location != null){
|
51
|
-
String latitude = String.valueOf(location.getLatitude());
|
52
|
-
textView.setText(latitude);
|
53
|
-
}else{
|
54
|
-
textView.setText("false");
|
55
|
-
} } } }); } }
|
56
|
-
```
|
57
|
-
デバックでは、pulic void onSuccess(Lication location)は、location == null となります。
|
1
変更コードを掲載
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,12 +7,11 @@
|
|
7
7
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
8
8
|
package="com.google.android.gms.location.sample.basiclocationsample" >
|
9
9
|
|
10
|
-
<uses-permission android:name="android.permission.
|
10
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
11
11
|
</manifest>
|
12
12
|
```
|
13
13
|
|
14
14
|
```MainActivity
|
15
|
-
|
16
15
|
public class MainActivity extends AppCompatActivity {
|
17
16
|
|
18
17
|
private FusedLocationProviderClient fusedLocationClient;
|
@@ -27,9 +26,32 @@
|
|
27
26
|
public void onSuccess(Location location) {
|
28
27
|
if(location != null){
|
29
28
|
Log.d("MSG","onSuccess");
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
29
|
+
} } }); } }
|
33
|
-
}
|
34
|
-
}
|
35
|
-
```
|
30
|
+
```
|
31
|
+
R011017
|
32
|
+
下記修正コードでpermissionの確認をしています。事前にディバイス側の位置情報の取得を認める設定をして動作確認しています。
|
33
|
+
```MainActivity
|
34
|
+
public class MainActivity extends AppCompatActivity{
|
35
|
+
|
36
|
+
FusedLocationProviderClient fusedLocationClient;
|
37
|
+
TextView textView;
|
38
|
+
|
39
|
+
@Override
|
40
|
+
protected void onCreate(Bundle savedInstanceState) {
|
41
|
+
super.onCreate(savedInstanceState);
|
42
|
+
setContentView(R.layout.activity_main);
|
43
|
+
|
44
|
+
textView = findViewById(R.id.textView);
|
45
|
+
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
46
|
+
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
|
47
|
+
fusedLocationClient.getLastLocation().addOnSuccessListener(this,new OnSuccessListener<Location>(){
|
48
|
+
@Override
|
49
|
+
public void onSuccess(Location location) {
|
50
|
+
if(location != null){
|
51
|
+
String latitude = String.valueOf(location.getLatitude());
|
52
|
+
textView.setText(latitude);
|
53
|
+
}else{
|
54
|
+
textView.setText("false");
|
55
|
+
} } } }); } }
|
56
|
+
```
|
57
|
+
デバックでは、pulic void onSuccess(Lication location)は、location == null となります。
|