1

Here all the codes. When I run this on emulator the application become closed . You can see my code I have used API Key and all the procedures but codes are not working. Please help me on this situation.

My XML Manifest code:

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

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

     <permission
        android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />


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

    <uses-permission android:name="com.vogella.android.locationapi.maps.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" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.example.mapviewdemo.MapViewDemoActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

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

</manifest>

My XML Layout code:

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

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportmapFragment"/>
</RelativeLayout> 

My Java code :

     package com.example.mapviewdemo;

        import android.os.Bundle;
        import android.app.Activity;
        import android.view.Menu;

        public class MapViewDemoActivity extends android.support.v4.app.FragmentActivity {

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



}
Beginner
  • 11
  • 1

3 Answers3

1

Your package name is

package="com.example.mapviewdemo"

But your packagename is the permissions used is wrong

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

According to the docs you don't need those permissions you can remove both the above permissions.

For more info

https://developers.google.com/maps/documentation/android/start

Also make sure you ahve referenced to the google play services library project properlyand make sure you have enabled maps for android in the google api console. Also google map api v2 is part of gooogle play services. SO you will require the same on your device

Quoting from the docs

http://developer.android.com/google/play-services/setup.html

If you want to test your app on the emulator, expand the directory for Android 4.2.2 (API 17) or a higher version, select Google APIs, and install it. Then create a new AVD with Google APIs as the platform target.

Note: Only Android 4.2.2 and higher versions of the Google APIs platform include Google Play services.

If you need further help it is better you post the logcat.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
1

You need to define permission correctly with the package name of your project:

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

And now you can use this define permission as:

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

Note: This permission is now completely un-necessary. The latest update of Google Play Services 3.1.59 made it useless. As a result, it can be removed.

Map Sample code:

If you would want to learn and explore Google Maps API v2 then you should download and run sample codes given in Google Play Services SDK.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

Actually the code is missing from the Activity which helps you renders the map. for crashes log cat is required

GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
        .getMap();

    if (map!=null){
      Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
          .title("Hamburg"));
      Marker kiel = map.addMarker(new MarkerOptions()
          .position(KIEL)
          .title("Kiel")
          .snippet("Kiel is cool")
          .icon(BitmapDescriptorFactory
              .fromResource(R.drawable.ic_launcher)));
    }

It will give some compilation error which you need to replace with your resources

Dinesh Prajapati
  • 9,274
  • 5
  • 30
  • 47
  • 1
    His problem is "When I run this on emulator the application become closed". Though he hasn't initialized a map, at least a blank screen should comes up. – Paresh Mayani Oct 01 '13 at 07:04
  • Correct. that's why I asked for the logcat and after that anyway the code is required to render. so advance help :) – Dinesh Prajapati Oct 01 '13 at 07:06