yuva ツ yuva ツ - 3 years ago 147
Android Question

Map activity in android

I have created map actvity.But its not showing map on mapview.just showing blank blocks.
is there any solution?

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"/>


activity code-

package com.example.googlemap;


import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {

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


manifest file-

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />

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

<meta-data
android:name="com.google.android.maps.v2.AIzaSyDRv4Ul_9iPW-roHIsc8EuxKwkRN8jWivs"
android:value="AIzaSyDRv4Ul_9iPW-roHIsc8EuxKwkRN8jWivs" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<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" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.googlemap.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>

<uses-library android:name="com.google.android.maps" />
</application>


after using this
i'm getting following exception-

08-22 23:19:52.204: E/AndroidRuntime(584): FATAL EXCEPTION: main
08-22 23:19:52.204: E/AndroidRuntime(584): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

Answer Source

Old MapView has been depreciated. You can't create a new Map key for publishing your app. You have to use new Google Maps for Android v2 API. Here's a link to the documents and example. https://developers.google.com/maps/documentation/android/start

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download