Android 谷歌地图在安卓棉花糖中不可见?
当在API级别大于23的情况下构建应用程序时,谷歌地图不会显示在marshmallow设备中,但它会正确显示在marshmallow版本下方。我使用了MapView 实际上,我在棉花糖中得到了当前的lat lang(0,0),这就是我在棉花糖中面临问题的原因。为了得到当前的lat lang,我使用以下行:- 私有void getCurrentLatLong(){Android 谷歌地图在安卓棉花糖中不可见?,android,google-maps,android-mapview,Android,Google Maps,Android Mapview,当在API级别大于23的情况下构建应用程序时,谷歌地图不会显示在marshmallow设备中,但它会正确显示在marshmallow版本下方。我使用了MapView 实际上,我在棉花糖中得到了当前的lat lang(0,0),这就是我在棉花糖中面临问题的原因。为了得到当前的lat lang,我使用以下行:- 私有void getCurrentLatLong(){ 首先授予应用权限,设置->你的应用->权限->启用需要权限 <uses-permission android:name="and
首先授予应用权限,设置->你的应用->权限->启用需要权限
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
以及Override on RequestPermissions Result
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_CODE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
// load your map here also
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
您介意显示您的代码吗?如果出现错误,请显示您的代码以及错误日志occured@LuizFernando Salvatera实际上,当我在23岁以上构建应用程序时,我并没有得到当前的lat lang its always(0,0)在marshmallow设备中,但在marshmallow之下,它的工作机制和编写代码以启用权限或在运行时加载map之前请求权限以避免问题我已经做了所有这些事情,但仍然面临这个问题。
if (ContextCompat.checkSelfPermission(Maps_Activity.this,Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(Maps_Activity.this, Manifest.permission.ACCESS_FINE_LOCATION)) {
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(Maps_Activity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},PERMISSION_REQUEST_CODE);
}
}
else{
//load your map here
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_CODE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
// load your map here also
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}