Android 尝试使用GoogleAppClient获取当前位置无效
我有一个简单的项目,通过Android 尝试使用GoogleAppClient获取当前位置无效,android,google-api-client,Android,Google Api Client,我有一个简单的项目,通过GoogleAppClient获得纬度和经度,我正在努力使它工作。这就是我目前所拥有的 格拉德尔: compile 'com.google.android.gms:play-services-maps:10.2.1' compile 'com.google.android.gms:play-services-plus:10.2.1' compile 'com.google.android.gms:play-services-location:10.2.1' 舱单: &l
GoogleAppClient
获得纬度和经度,我正在努力使它工作。这就是我目前所拥有的
格拉德尔:
compile 'com.google.android.gms:play-services-maps:10.2.1'
compile 'com.google.android.gms:play-services-plus:10.2.1'
compile 'com.google.android.gms:play-services-location:10.2.1'
舱单:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
结果日志为空,我不确定可能是什么,可能是权限?谢谢 对于Api Marshmallow及以上版本,授予运行时权限如下:
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
// do your work
} else {
// request permission.
ActivityCompat.requestPermissions(this, new String[]
{
Manifest.permission.ACCESS_FINE_LOCATION}, MY_LOCATION_REQUEST_CODE);
}
public void onRequestPermissionsResult(int requestCode, String[]
permissions, int[] grantResults) {
if (requestCode == MY_LOCATION_REQUEST_CODE) {
if (permissions.length == 1 &&
permissions[0] == Manifest.permission.ACCESS_FINE_LOCATION &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
/// granted do your work
} else {
// Permission was denied. Display an error message.
}
}
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
// do your work
} else {
// request permission.
ActivityCompat.requestPermissions(this, new String[]
{
Manifest.permission.ACCESS_FINE_LOCATION}, MY_LOCATION_REQUEST_CODE);
}
public void onRequestPermissionsResult(int requestCode, String[]
permissions, int[] grantResults) {
if (requestCode == MY_LOCATION_REQUEST_CODE) {
if (permissions.length == 1 &&
permissions[0] == Manifest.permission.ACCESS_FINE_LOCATION &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
/// granted do your work
} else {
// Permission was denied. Display an error message.
}
}