Android百度地图无法定位问题
Android使用百度定位
在使用百度定位sdk时按照百度官方开发指南:
http://lbs.baidu.com/index.php?title=androidsdk/guide/create-map/location
确迟迟无法做到定位,都是如下所示:
多方查找求证后才回过神来——还有权限没开,动态请求下权限就好了。
将以下方法在主activity里声明,在oncreat里调用。
private void iniPermission(){
List<String> permissionList=new ArrayList<>();
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.
permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.
permission.READ_PHONE_STATE)!= PackageManager.PERMISSION_GRANTED){
permissionList.add(Manifest.permission.READ_PHONE_STATE);
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.
permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (!permissionList.isEmpty()){
String[] permissions=permissionList.toArray(new String[permissionList.size()]);
ActivityCompat.requestPermissions(MainActivity.this,permissions,1);
}
}