0

I worked on Google Map and use Fragment not Fragmentactivity but not working . my code given below.

map.xml

**<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >
 <com.google.android.gms.maps.MapView
            android:id="@+id/mapview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>**

Map.java

public class Maps extends Fragment {

    MapView m;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // inflat and return the layout
        View v = inflater.inflate(R.layout.maps, container, false);
        m = (MapView) v.findViewById(R.id.mapview);
        m.onCreate(savedInstanceState);

        return v;
    }

    @Override
    public void onResume() {
        super.onResume();
        m.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        m.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        m.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        m.onLowMemory();
    }
}

manifest

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

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

    <uses-permission android:name="android.permission.INTERNET" />
    <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-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <permission
        android:name="com.example.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.permission.MAPS_RECEIVE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="com.tech.Conference.SplashScreen"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.technostacks.Conference.MainActivity"
            android:logo="@drawable/menu_icon"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme" >
        </activity>
    </application>

</manifest>

this code but not success. Gettin error like this..

java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
Cœur
  • 37,241
  • 25
  • 195
  • 267
ckpatel
  • 1,926
  • 4
  • 18
  • 34

2 Answers2

0

you have to add one more meta-data in your Manifest.xml

        meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="your key"
Rajesh Mikkilineni
  • 854
  • 10
  • 22
  • thanks but when i add this then get error like – ckpatel Jul 19 '14 at 08:58
  • check with the google-play-services is refereed correctly or not. if your getting error at android:value="@integer/google_play_services_version means your Google-Play-Services_lib reference is not working check this link http://stackoverflow.com/questions/19879844/adding-google-play-services-version-to-your-apps-manifest – Rajesh Mikkilineni Jul 19 '14 at 09:00
0

You have used mapv1 which is deprecated , use mapv2

Richa
  • 3,165
  • 1
  • 22
  • 26