Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have tried to use Google map API V2 in my android mobile application and I used the article which was guide how to do it..But still I failed to load the map into my app.

my manifest is


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >

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

<uses-permission android:name="com.example.map.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-feature>
android:glEsVersion="0x00020000"
android:required="true"/>


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

<application>
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity>
android:name="com.example.map.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN">

<category android:name="android.intent.category.LAUNCHER">



<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key"/>




my activiyu_main

<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"
tools:context=".MainActivity" >

<textview>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />

<fragment>
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment" />



and my main activity.java is

package com.example.map;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends Activity {


private GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


try {
// Loading map
initilizeMap();

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

private void initilizeMap() {
// TODO Auto-generated method stub
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().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();
}
}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

}

My logCAT is

01-24 09:46:14.271: W/Trace(962): Unexpected value from nativeGetEnabledTags: 0
01-24 09:46:14.271: W/Trace(962): Unexpected value from nativeGetEnabledTags: 0
01-24 09:46:14.571: W/Trace(962): Unexpected value from nativeGetEnabledTags: 0
01-24 09:46:14.571: W/Trace(962): Unexpected value from nativeGetEnabledTags: 0
01-24 09:46:15.181: D/AndroidRuntime(962): Shutting down VM
01-24 09:46:15.181: W/dalvikvm(962): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
01-24 09:46:15.251: E/AndroidRuntime(962): FATAL EXCEPTION: main
01-24 09:46:15.251: E/AndroidRuntime(962): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map/com.example.map.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.os.Looper.loop(Looper.java:137)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-24 09:46:15.251: E/AndroidRuntime(962): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 09:46:15.251: E/AndroidRuntime(962): at java.lang.reflect.Method.invoke(Method.java:511)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-24 09:46:15.251: E/AndroidRuntime(962): at dalvik.system.NativeStart.main(Native Method)
01-24 09:46:15.251: E/AndroidRuntime(962): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
01-24 09:46:15.251: E/AndroidRuntime(962): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.Activity.setContentView(Activity.java:1881)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.example.map.MainActivity.onCreate(MainActivity.java:23)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.Activity.performCreate(Activity.java:5104)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-24 09:46:15.251: E/AndroidRuntime(962): ... 11 more
01-24 09:46:15.251: E/AndroidRuntime(962): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.maps.internal.q.v(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.maps.internal.q.u(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.maps.MapFragment$b.eb(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.dynamic.a.a(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.app.Activity.onCreateView(Activity.java:4716)
01-24 09:46:15.251: E/AndroidRuntime(962): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
01-24 09:46:15.251: E/AndroidRuntime(962): ... 21 more

Any help is really appreciate

Thanks
Posted

Check out this explanation and example.
http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html[^]

Don't forget to get your own Android API key for Google Maps v2:
https://developers.google.com/maps/documentation/android/start[^]

Good luck!
 
Share this answer
 
Required permission in android Manifest.xml file
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" xmlns:android="#unknown">
 
Share this answer
 
Android Required a permission for the map fragment

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" xmlns:android="#unknown">
in Manifest.xml file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900