4

I want to display map in android emulator. For that i Installed Google play services and import it in workspaces and make them references in my project. But i run application it shows Goolgle play services in not in Your phone. I am not able to understand why it shows. I am attaching full code here..
Here is my 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" />

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

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

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

</manifest>

main.xml

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >



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

</RelativeLayout>

.java file is here

package com.example.map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity 
{



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

    }
![enter image description here][1]
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

emulator image Could you give me answer why it shows. It really help me.

Bhavin Nattar
  • 3,189
  • 2
  • 22
  • 30
Deepak Borade
  • 191
  • 2
  • 5
  • 15
  • If you go into Project -> Properties -> Android, is your build target a Google APIs target or an Android target? – haventchecked Aug 09 '13 at 12:24
  • Check this link it help me: [1]: http://stackoverflow.com/questions/5262695/how-to-get-md5-from-debug-keystore-file/5262845#5262845 [2]: http://stackoverflow.com/questions/6305938/how-can-i-get-the-md5-fingerprint-from-javas-keytool-not-only-sha-1 – KOTIOS Aug 09 '13 at 12:25
  • in emulator google map doesn't show. – Shani Goriwal Aug 09 '13 at 12:38

3 Answers3

3

Point 1. Use below code if you are developing app for API level 8.

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

see MapFragment. Use this class only if you are targeting API 12 and above. Otherwise, use SupportMapFragment.

Point 2. Extend your class with FragmentActivtiy instead of Activity

private GoogleMap googleMap;

    public void loadGoogleMap(){
        if(googleMap==null){
              // Getting Google Play availability status
              int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
              // Showing status
              if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available
                  int requestCode = 10;
                  Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, (Activity)context, requestCode);
                  dialog.show();
              }else{
                // Getting reference to the SupportMapFragment of activity_main.xml
                  SupportMapFragment fm = (SupportMapFragment) this.YOUR_CLASS_NAME.getSupportFragmentManager()
                        .findFragmentById(R.id.my_comm_nearme_map);

                  // Getting GoogleMap object from the fragment
                  googleMap = fm.getMap();

                  //setting map type
                  googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

                  UiSettings uiSettings = googleMap.getUiSettings();
                  uiSettings.setCompassEnabled(false);
                  uiSettings.setZoomControlsEnabled(true);
                  uiSettings.setMyLocationButtonEnabled(false);
              }
        }
    }

Point 3.

But i run application it shows Goolgle play services in not in Your phone.

Android need Google Play services in order to run maps. You can download it from market, and try again, Maps will work.

If you get error while installing Google Play services , then your device is not compatible.

Androider
  • 2,884
  • 5
  • 28
  • 47
1

enter image description herePlease go to google api and ON the Google Maps Android API v2 Only

Google API Console -> Service -> Google Maps Android API v2 ->

than generte new API Key and test.

Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
0

use this code to run customized google map on below api level-11 it also runs successfully on higher versions.

import google-play-services_lib project into your workspace from \sdk\extras\google\google_play_services_froyo\libproject .

right click to the project->properties->android->right click the check box in library panel name as "is library" and click apply and press ok.

now go to your projects property-android->in library panel->click add->now select "google-play-services_lib" in option->apply>ok

Now use this code

    package com.hmkcode.android;

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

   import com.google.android.gms.maps.CameraUpdateFactory;
   import com.google.android.gms.maps.GoogleMap;
   import com.google.android.gms.maps.SupportMapFragment;
   import com.google.android.gms.maps.model.BitmapDescriptorFactory;
   import com.google.android.gms.maps.model.LatLng;
   import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity {

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

        try {
            GoogleMap map;
            map = ((SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
                    19.233442, 72.980851), 16));
            map.addMarker(new MarkerOptions()
                    .icon(BitmapDescriptorFactory
                            .fromResource(R.drawable.house_flag))
                    .anchor(0.0f, 1.0f)
                    .position(new LatLng(19.233442, 72.980851))
                    .title("Hello world"));

        } catch (NullPointerException e) {

        }

    }

}

layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

</LinearLayout>

in manifest

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

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

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

    <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"/>
    <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.hmkcode.android.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>
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="use your obtained key" />

        <meta-data android:name="com.google.android.gms.version"
             android:value="@integer/google_play_services_version" />
    </application>

</manifest>

now you can see the map else you will see button which can be used to update the services.

shiv
  • 625
  • 1
  • 6
  • 12