I am trying to run android google map
in android app but not able to run it , I follow all the procedure and I created the API Key as Well . Following is the Code:
MainActivity.java
:
public class MainActivity extends Activity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
initializeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressLint("NewApi")
private void initializeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
if (googleMap == null) {
Toast.makeText(getApplicationContext(), "Sorry, Unable to Show Map", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onResume() {
super.onResume();
initializeMap();
}
}
And The AndroidManifest.xml
File is As Follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapv2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<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" >
<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>
<!-- Google Map Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAxgtuqq30RxWs0jUtq8X6BNgbA1bkehUY" >
</meta-data>
</application>
My activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
And Logcat as Follows:
08-13 12:27:56.205: E/AndroidRuntime(738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-13 12:27:56.205: E/AndroidRuntime(738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-13 12:27:56.205: E/AndroidRuntime(738): at dalvik.system.NativeStart.main(Native Method)
0 comments:
Post a Comment