1

This is the code i have copied from the sample map application even the sample map application is not showing the map.

So i separately copied and pasted the code with my API key. This time also its not showing the map.

Main Activity

package com.example.map;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

    private GoogleMap mMap;

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

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }

    private void setUpMap() {
        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    }
}

XML FILE

<?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"
  class="com.google.android.gms.maps.SupportMapFragment"/>

Android Manifest file

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

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

  <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"/>
  <!-- External storage for caching. -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <!-- My Location -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <!-- Maps API needs OpenGL ES 2.0. -->
  <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" >

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

    <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" />
            </intent-filter>
    </activity>
    </application>
</manifest>

OUT PUT:

https://i.stack.imgur.com/CzKs5.png

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
Raaja
  • 97
  • 2
  • 7
  • 1
    do you get any exceptions does you app crash? – Raghunandan Aug 29 '13 at 12:16
  • Make sure the API key you used is for maps and not other google apis. maybe [this](http://stackoverflow.com/questions/18498107/android-blank-page-when-using-google-map-api-2) is related to your problem? – linus Aug 29 '13 at 16:05
  • no my app is not crashing its not showing the map – Raaja Aug 30 '13 at 04:38
  • how can i identify its map api or not, i created api key from Google developer website – Raaja Aug 30 '13 at 04:42
  • try this link may be useful for u http://venkoolit.blogspot.in/2013/05/tutorial-for-develop-google-maps-in-api.html – Venky Aug 30 '13 at 05:23
  • hi venky ur tutorial seems to be more clear. While adding the below code i got error in this line espeially in fragment areas SupportMapFragment smf = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); GoogleMap map = smf.getMap(); – Raaja Aug 30 '13 at 05:57

3 Answers3

0

Try to add those two permissions:

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

and try to test this application on a real device.

Seeing your stack-trace would be useful top.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
0
I changed the code like this

**Manifest**

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

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

  <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"/>
  <!-- External storage for caching. -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <!-- My Location -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


  <permission android:name="com.example.map.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> 
  <uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/>
  <!-- Maps API needs OpenGL ES 2.0. -->
  <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" >

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

    <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" />
            </intent-filter>
    </activity>
    </application>
</manifest>





**LOGCAT**

Again the map is not showing

08-30 10:20:30.444: I/Choreographer(1166): Skipped 30 frames!  The application may be doing too much work on its main thread.

08-30 10:20:30.724: D/dalvikvm(1166): GC_FOR_ALLOC freed 302K, 11% free 3645K/4056K, paused 72ms, total 95ms

08-30 10:20:31.084: D/dalvikvm(1166): GC_FOR_ALLOC freed 154K, 13% free 3655K/4188K, paused 200ms, total 201ms

08-30 10:20:31.474: D/dalvikvm(1166): GC_FOR_ALLOC freed 286K, 16% free 3524K/4188K, paused 150ms, total 174ms

08-30 10:20:31.554: D/dalvikvm(1166): GC_FOR_ALLOC freed 154K, 16% free 3522K/4188K, paused 31ms, total 31ms

08-30 10:20:31.625: D/dalvikvm(1166): GC_FOR_ALLOC freed 152K, 16% free 3522K/4188K, paused 45ms, total 45ms

08-30 10:20:31.674: D/dalvikvm(1166): GC_FOR_ALLOC freed 172K, 16% free 3523K/4188K, paused 31ms, total 32ms

08-30 10:20:31.734: D/dalvikvm(1166): GC_FOR_ALLOC freed 152K, 16% free 3523K/4188K, paused 32ms, total 33ms

08-30 10:20:31.794: D/dalvikvm(1166): GC_FOR_ALLOC freed 152K, 16% free 3523K/4188K, paused 45ms, total 46ms

08-30 10:20:31.854: D/dalvikvm(1166): GC_FOR_ALLOC freed 152K, 16% free 3523K/4188K, paused 35ms, total 37ms




**Console**
[2013-08-30 10:20:22 - MAp] ------------------------------

[2013-08-30 10:20:22 - MAp] Android Launch!

[2013-08-30 10:20:22 - MAp] adb is running normally.

[2013-08-30 10:20:22 - MAp] Performing com.example.map.MainActivity activity launch

[2013-08-30 10:20:22 - MAp] Automatic Target Mode: Unable to detect device compatibility. 

Please select a target device.

[2013-08-30 10:20:25 - MAp] Application already deployed. No need to reinstall.

[2013-08-30 10:20:25 - MAp] Starting activity com.example.map.MainActivity on device 
emulator-5556

[2013-08-30 10:20:27 - MAp] ActivityManager: Starting: Intent { 
act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] 
cmp=com.example.map/.MainActivity }
Raaja
  • 97
  • 2
  • 7
0

Add in your manifest file - uses-permission android:name="com.example.map.permission.MAPS_RECEIVE" Add Api key which is given as you got in : Key for browser apps (with referers)

on clicking from "API Access" https://code.google.com/apis/console/?pli=1#project:606531687416:access

Also check all the valid services for map. like Google Maps Android API v2 from services menu from the link. Hope it will work.

swati srivastav
  • 635
  • 4
  • 15