8

i use the google map v2 and display the multiple marker but first i want to display the map on the screen i put down my all the files here is gives only blank i will check it out all but nothing work for me

enter image description here

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/mapview"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

AndroidManifest.xml

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

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />  
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />        
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <permission
        android:name="com.example.stiptis.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.stiptis.permission.MAPS_RECEIVE"/>

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

</manifest>

Activity class

public class MainActivity extends FragmentActivity {

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

    }



}
start android
  • 323
  • 7
  • 21
  • [**This**](http://rdcworld-android.blogspot.in/2012/07/google-map-tutorial-android-advance.html) may help you – swiftBoy Apr 12 '13 at 07:11

4 Answers4

6

Probably there is a problem with your Maps API Key. Put this function into your activity, and see what it logs for the correct SHA key:

 private void getShaKey() {

 try {
 PackageInfo info = getPackageManager().getPackageInfo("your.package.name",
 PackageManager.GET_SIGNATURES);
 for (Signature signature : info.signatures) {
 MessageDigest md = MessageDigest.getInstance("SHA");
 md.update(signature.toByteArray());
 Log.v(TAG, "KeyHash:" + Base64.encodeToString(md.digest(),
 Base64.DEFAULT));
 }
 } catch (NameNotFoundException e) {
 e.printStackTrace();

 } catch (NoSuchAlgorithmException e) {
 e.printStackTrace();

 }

 }
Analizer
  • 1,594
  • 16
  • 30
  • 04-12 12:49:15.783: E/Google Maps Android API(28634): Failed to load map. Could not contact Google servers. – start android Apr 12 '13 at 07:19
  • Did you sign your app with your debug keystore or an other one? Did you include google play services lib as a library project? – Analizer Apr 12 '13 at 07:22
  • 3
    Make sure the "Google Maps Android API v2", not "Google Maps API v2" is enabled and re-generate the API key if so – Analizer Apr 12 '13 at 07:25
  • If your map is working properly, than it's fine :) But the getShaKey() function I wrote in my answer logs the correct key if you run it. – Analizer Apr 12 '13 at 10:30
  • i got the solution i create new api key with other account now is work thanks – start android Apr 12 '13 at 10:48
  • did you change the "your.package.name" argument? did you debug it? is it a standard android device? – Analizer May 12 '15 at 14:50
0

In case you tried the map example from sdk extras, you may find this answer helpful.

Community
  • 1
  • 1
denispyr
  • 1,403
  • 3
  • 21
  • 34
  • It seems that the system flagged you down for posting the same answer twice. Can you elaborate on each of them to make it clearer and more applicable to each question? – nanofarad Oct 17 '13 at 21:55
0

There Also the probability to be name package problem used for android key generation

0

This prints out the signature and package name that you need to enter in Google Developers Console to generate API key:

private void getShaKey() {
    try {
      Activity activity = this; // or getActivity() if the code is in fragment
      String packageName = activity.getPackageName();
      PackageInfo info = activity.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
      for (android.content.pm.Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA1");
        md.update(signature.toByteArray());
        byte[] digest = md.digest();
        Log.v(LOG_TAG, "KeyHash: " + bytesToHex(digest) + ";" + packageName);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static String bytesToHex(byte[] bytes) {
    char[] hexArray = "0123456789ABCDEF".toCharArray();
    char[] hexChars = new char[bytes.length * 2];
    for (int j = 0; j < bytes.length; j++) {
      int v = bytes[j] & 0xFF;
      hexChars[j * 2] = hexArray[v >>> 4];
      hexChars[j * 2 + 1] = hexArray[v & 0x0F];
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < hexChars.length; i += 2) {
      sb.append(hexChars[i]);
      sb.append(hexChars[i + 1]);
      if (i < hexChars.length - 2) {
        sb.append(':');
      }
    }
    return sb.toString();
  }

Look for KeyHash: in the logs.

This is modification of Analizer's code.

peceps
  • 17,370
  • 11
  • 72
  • 79