Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:不使用Fragment或MapsActivity显示地图视图_Java_Android_Google Maps_Android Gradle Plugin - Fatal编程技术网

Java Android:不使用Fragment或MapsActivity显示地图视图

Java Android:不使用Fragment或MapsActivity显示地图视图,java,android,google-maps,android-gradle-plugin,Java,Android,Google Maps,Android Gradle Plugin,我想显示地图视图,但地图视图始终为灰色,左下角有谷歌图标。有人告诉我,如果活动实现OnMapReadyCallBack(),我们可以在不使用MapsActivity的情况下使用MapView。 我不知道我错过了什么 这是我的应用程序gradle文件 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "24.0.3" defaultCo

我想显示地图视图,但地图视图始终为灰色,左下角有谷歌图标。有人告诉我,如果活动实现OnMapReadyCallBack(),我们可以在不使用MapsActivity的情况下使用MapView。 我不知道我错过了什么

这是我的应用程序gradle文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.3"

    defaultConfig {
        applicationId "pls.annesophie.androidvoyagesmets"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.android.support:appcompat-v7:23.4.0'


}
    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
这是我的gradle项目文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.3"

    defaultConfig {
        applicationId "pls.annesophie.androidvoyagesmets"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.android.support:appcompat-v7:23.4.0'


}
    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
我的活动:

public class DetailActivity extends AppCompatActivity implements OnMapReadyCallback {

private GoogleMap map;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);


    // Gets the MapView from the XML layout and creates it
    MapView mapView = (MapView) findViewById(R.id.map);
    mapView.onCreate(savedInstanceState);

    // Gets to GoogleMap from the MapView and does initialization stuff
    map = mapView.getMap();
    map.getUiSettings().setMyLocationButtonEnabled(false);
    map.setMyLocationEnabled(true);
    MapsInitializer.initialize(DetailActivity.this);
    onMapReady(map);

    // Updates the location and zoom of the MapView
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
    map.animateCamera(cameraUpdate);

//A lot of non pertinent things i think
}

@Override
public void onMapReady (GoogleMap map){
    this.map = map;
    map.setMyLocationEnabled(true);
}
谢谢你的帮助