0

I'm just trying to see a map in my android app and i'm having some troubles. I've been following severals tutorial and still a have no result. I downloaded google play services from my sdk manager and imported google_play_services_lib correctly i guess. So i created a Google Maps API Key from Google Api Console using my packagename and my SHA1, which i found using cmd and also in eclipse in window>preferences>android>build, i got the same SHA1 in both ways so i think it's correct.

So i set my manifest like this

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapprova"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="21" />

<permission android:name="com.example.googlemapprova.permission.MAPS_RECEIVE"
     android:protectionLevel="signature"/>
<uses-permission android:name="com.example.googlemapprova.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="my api key" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

in my layout file i created just a map fragment

    <fragment
    android:id="@+id/map"
    class="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignTop="@+id/textView1"
    android:layout_centerHorizontal="true" />

I've changed android:name with class="com.google.android.gms.maps.SupportMapFragment" because of a tutorial

And then my main

package com.example.googlemapprova;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity {

GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    try {
        // Loading map
        initilizeMap();
        initializeUiSettings();
        initializeMapLocationSettings();
        initializeMapTraffic();
        initializeMapType();
        initializeMapViewSettings();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

@Override
protected void onResume() {
    super.onResume();
    // initilizeMap();
}

private void initilizeMap() {

    googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    // check if map is created successfully or not
    if (googleMap == null) {
        Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
    }
}

public void initializeUiSettings() {
    googleMap.getUiSettings().setCompassEnabled(true);
    googleMap.getUiSettings().setRotateGesturesEnabled(false);
    googleMap.getUiSettings().setTiltGesturesEnabled(true);
    googleMap.getUiSettings().setZoomControlsEnabled(true);
    googleMap.getUiSettings().setMyLocationButtonEnabled(true);
}

public void initializeMapLocationSettings() {
    googleMap.setMyLocationEnabled(true);
}

public void initializeMapTraffic() {
    googleMap.setTrafficEnabled(true);
}

public void initializeMapType() {
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}

public void initializeMapViewSettings() {
    googleMap.setIndoorEnabled(true);
    googleMap.setBuildingsEnabled(false);
}

}

i got the code in my main from a tutorial and modified it just a little, in this way i managed my app to not crash(if i don't use this code my app will crash). this is what i get i'm using a motorola moto g3 phone to try it So i tryed to download aLogcat on my phone from play store, but i get nothing on it, maybe i'm using it in the wrong way. this is the tutorial i used the most

Can someone help me to view a map on my app? I can't understand why it's not working I'm trying to get the Logcat now

Lucas
  • 35
  • 1
  • 5
  • Can u read this and try https://developers.google.com/maps/documentation/android-api/start#the_maps_activity_java_file – Raghavendra May 17 '16 at 09:41
  • Try to check the code in this SO question [17469661](http://stackoverflow.com/questions/17469661/google-mapfragment-not-working-in-android) and [15703245](http://stackoverflow.com/questions/15703245/google-maps-fragment-doesnt-load) if it can help you. Also make sure you have referenced google play services library project properly. – KENdi May 18 '16 at 12:03
  • thak you all, i tryed to use android studio instead of eclipse and every thing worked perfectly. In another stack overflow question someone told eclipse couldnt read correctly the meta-data tags. So now i'm using android studio and it works – Lucas May 18 '16 at 12:51

1 Answers1

0

Your map fragment is loaded, but map content does not.

Where you placed your API key?

<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="my api key" />
Bozic Nebojsa
  • 3,606
  • 1
  • 19
  • 17