Thursday, 2 August 2018

Android : Google Maps API V2 displays black screen ECLIPSE

I am trying to show my current location on google maps but it displays black screen in the map fragment.

my manifest file

<?xml version="1.1" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.edraky.tasksheet"
    android:versionCode="13"
    android:versionName="6.7" >
    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="26" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.edraky.tasksheet.MAPS_RECEIVE" />
    <permission
        android:name="com.edraky.tasksheet.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.edraky.tasksheet.permission.MAPS_RECEIVE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/transparentlogo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".SplashScreenActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login" >
        </activity>      
        <activity
            android:name=".ContactUs_Activity"
            android:label="@string/title_activity_contact_us" >
        </activity>
        <activity
            android:name=".AboutUs_Activity"
            android:label="@string/title_activity_about_us_"
            android:noHistory="false" >
        </activity>
        <activity
            android:name=".WelcomePage"
            android:label="@string/title_activity_welcome_page" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" /> 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDpP-HMGNQCnFPnzODgTiJFXs00yirfhHE" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>
</manifest>

ContactUs Layout ( layout displaying the map )

Contact us layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.edraky.tasksheet.ContactUsActivity">
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_marginTop="40dp"
        android:layout_height="260dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:textStyle="bold|italic"
        android:textSize="11dp"
        android:textIsSelectable="true" />
    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="24dp"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:scrollbars="vertical" />
    <Button
        android:id="@+id/homebutton"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/contactusicon" />
</RelativeLayout>

contact us activity class

public class ContactUs_Activity extends FragmentActivity {
                GoogleMap mMap;
                GPSTracker gps;
                Double currLat;
                Double currLong;
                GMapV2Direction gmap;
                Button homebutton;
                TextView view1;

                @Override

                protected void onCreate(Bundle savedInstanceState) {

                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_contact_us);
                                homebutton = (Button) findViewById(R.id.homebutton);
                                view1 = (TextView) findViewById(R.id.textView1);
                                view1.setText("Text Shown");
                                homebutton.setOnClickListener(new OnClickListener() {
                                                @Override
                                                public void onClick(View v) {
                                                                onBackPressed();
                                                }
                                });
                                SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
                                mMap = mapFragment.getMap();
                                gps = new GPSTracker(this);
                                currLat = gps.getLatitude();
                                currLong = gps.getLongitude();
                                LatLng sydney = new LatLng(currLat, currLong);
                                mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
                                mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));    
                }
}

i included all the libraries and generated the API key

API key

output is shown below

Output

no error message is logged. what could possibly go wrong in displaying the map ?

Note : same code is working on another application with different API key ofcourse and map is displayed correctly.

IMPORTANT NOTE:The app was already published on google play store before adding the Maps SDK API,so is there any modifications that I should do considering that or its irrelative?



from Android : Google Maps API V2 displays black screen ECLIPSE

No comments:

Post a Comment