How to display Map on emulator
Asked Answered
V

2

9

From Android Studio, I created a Map Activity project; so, there's no custom code.

The only custom changes made was copying the URL from the google_maps_api.xml _(https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=)_ and using it to create an API key.

Android Studio: 3.0.1 Emulator: Nexus 5X with API 25

Build.gradle file


apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "xxxx.xxx.xxxx"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.android.gms:play-services-maps:11.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Screenshot

enter image description here

It seems like I'm missing something; I just don't know what it is.

Verile answered 29/1, 2018 at 6:53 Comment(9)
I think that you are using wrong API key.Not displaying usually happens because of it.Onshore
developers.google.com/maps/documentation/android-api/startBorderer
The API key was generated using the URL in the google_maps_api.xml file autogenerated from Android Studio.I'm not sure how it could be wrong.Verile
@AswinPAshok Thanks for the link; however, it's the same one I used and I still got this blank screen.Verile
Try to run in your mobile. Sometimes emulator is not able to load map properly, That's why it shows blank map without loading roots.Myriammyriameter
@Myriammyriameter Have your comment as an answer and I'll mark it. Running the same codebase on a device absolutely worked!Verile
Are your sure your virtual device have target Google APIs?Gaseous
@Verile Thankss a lotMyriammyriameter
@Gaseous Yes, the device is. I'm able to access some API services.Verile
M
3

Try to run in your mobile. Sometimes emulator is not able to load map properly, That's why it shows blank map without loading roots.

Myriammyriameter answered 29/1, 2018 at 9:1 Comment(0)
G
0

you can see the map on the emulator.

you just need to follow the below steps.

Enable Google Play services: By default, the Android emulator does not include Google Play services, which are required for displaying maps.

You can create a new emulator with Google Play services support or modify an existing one. To modify an existing emulator, open the AVD Manager, select the emulator, and click on the "Edit" button. In the Virtual Device Configuration, under the "Emulated Performance" section, check the "Play Store" option. Save the changes and start the emulator. hope it will work.

Giralda answered 26/5, 2023 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.