Lisda Wijayanti
Lisda Wijayanti

Reputation: 63

Google Maps on Android not showing anything

I got some problem when trying a google maps on android activity. When I run the project the activity doesn't show anything, only a blank activity. I try to search the solution, and try to fix it with adding a new permission like

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

And try to change the API key with the new one. But all of them are failed. I read some solution in stackoverflow which say to MAKE SURE THE PACKAGE NAME in the credential(but this one I dont get it). Could some one help me.

Here is my activity code

package com.wahana.wahanamarketingclub.activities

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.google.android.gms.maps.*
import com.google.android.gms.maps.OnMapReadyCallback

import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import com.wahana.wahanamarketingclub.R

class EventActivity : AppCompatActivity(), OnMapReadyCallback {

private lateinit var mMap: GoogleMap

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_event)
    // Obtain the SupportMapFragment and get notified when the map is ready 
to be used.
    val mapFragment = supportFragmentManager
            .findFragmentById(R.id.map) as MapFragment
    mapFragment.getMapAsync(this)
}

/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the 
 camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be 
 prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once 
 the user has
 * installed Google Play services and returned to the app.
 */
   override fun onMapReady(googleMap: GoogleMap) {
    mMap = googleMap

    // Add a marker in Sydney and move the camera
    val sydney = LatLng(-34.0, 151.0)
    mMap.addMarker(MarkerOptions().position(sydney).title("Marker in 
    Sydney"))
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
}

}

Mamnifest

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- <uses-permission android:name="android.permission.CAMERA" /> -->

<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>



<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!-- android:theme="@style/AppTheme"> -->
    <activity android:name=".activities.MainActivity" />
    <activity android:name=".activities.AboutUs" />
    <activity android:name=".activities.CatalogActivity" />
    <activity android:name=".activities.EventActivityNina" />
    <activity android:name=".activities.HistoryActivity" />
    <activity android:name=".activities.ActivitySalesmanActivity" />
    <activity android:name=".activities.QuizActivity" />
    <activity android:name=".activities.RewardActivity" />
    <activity android:name=".activities.TrainingScheduleActivity" />
    <activity android:name=".activities.ReportActivity" />
    <activity android:name=".activities.SurveyActivity" />
    <activity android:name=".activities.CustomerActivity" />
    <activity android:name=".activities.EditProfileActivity" />
    <activity android:name=".activities.ChangePasswordActivity" />
    <activity android:name=".activities.SplashScreenActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".activities.LoginActivity" />
    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".activities.EventActivity"
        android:label="@string/title_activity_event"></activity>
</application>

Upvotes: 0

Views: 2940

Answers (3)

Nsubuga
Nsubuga

Reputation: 71

Just in case you are doing it on Android 9.0, there is an issue as noted here , So you find this solution useful

Upvotes: 0

Rajesh Kumar
Rajesh Kumar

Reputation: 11

Make sure u have added the sha1 key in configuration console.developer.google.com for project. It was necessary to provide sha1 key

Upvotes: 1

Deni Rohimat
Deni Rohimat

Reputation: 162

Make sure your package name on console.developer.google.com is right and same with your package name com.wahana.wahanamarketingclub

The other one is make sure you has been enable Google Maps Android API. If you has enable it, you will see like this enter image description here

If still not working, please add your logcat for more information here

Upvotes: 0

Related Questions