-1

I don't know what my problem is, the Google map is not showing

look

I have change the project property to Google API 2.3.3 and no errors are displaying

here's my code:

Mapping.java

package com.mapping;

import java.io.IOException;
import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class Mapping extends MapActivity {

    private MapView mapView = null;
    private Geocoder geoCoder = null;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        // latitude and longitude of Dallas, TX
        // set as starting point 
        int lat = (int)(37.422006 * 1000000); //the geocoder requires integers...
        int lon = (int)(-122.084095 * 1000000);
        //make these into a GeoPoint:
        GeoPoint startPoint = new GeoPoint(lat, lon);
        mapView.getController().setZoom(12);
        mapView.getController().setCenter(startPoint);

        geoCoder = new Geocoder(this);
    }

    public void mapHandler(View v) {
        switch(v.getId()) {
        case R.id.btnSat:
            mapView.setSatellite(true);
            break;
        case R.id.btnTraf:
            mapView.setTraffic(true);
            break;
        case R.id.btnNorm:
            mapView.setSatellite(false);
            mapView.setTraffic(false);
            break;          
        }
    }

    public void geocode(View v) {
        EditText geoLocation = (EditText) findViewById(R.id.txtLocation);
        if(Geocoder.isPresent()) {
            try {
                String addr = geoLocation.getText().toString();

                List<Address> locationList = geoCoder.getFromLocationName(addr, 5);
                if(locationList != null && locationList.size() > 0) {
                    int lat = (int)(locationList.get(0).getLatitude() * 1000000);
                    int lon = (int)(locationList.get(0).getLongitude() * 1000000);

                    GeoPoint setPoint = new GeoPoint(lat, lon);
                    mapView.getController().setZoom(14);
                    mapView.getController().setCenter(setPoint);
                }
            } catch (IOException error) {
                Log.i("Caught IOException", "-----Printing Stack Trace-----");
                error.printStackTrace();
            }
        } else {
            geoLocation.setText("No Geocoder Available");
        }
    }

    protected boolean isLocationDisplayed() {
        return false;
    }

    protected boolean isRouteDisplayed() {
        return false;
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btnSat" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Satellite"
            android:onClick="mapHandler" />

        <Button 
            android:id="@+id/btnTraf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Traffic"
            android:onClick="mapHandler" />

        <Button 
            android:id="@+id/btnNorm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Normal"
            android:onClick="mapHandler" />

    </LinearLayout>

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/txtLocation"
            android:layout_width="200sp"
            android:layout_height="wrap_content"
            android:text="Dallas" />

        <Button 
            android:id="@+id/btnGeocode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Find Location"
            android:onClick="geocode" />

    </LinearLayout>

    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:apiKey="0G_pKeFNWX5lw7PQ7AzKnl2XbRs7bHZ3p6ECosQ" />
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mapping"
    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.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <activity
            android:label="@string/app_name"
            android:name=".Mapping" >
            <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>

</manifest>

Can anyone help me? I've pulling my hair all day. The program is running okay, as you can see I was able to take a screen shot so it must be the connection of the device to the Google API. I can't seem to find the error...

Dipsomania
  • 73
  • 11
philip
  • 1,292
  • 3
  • 24
  • 44
  • 2
    did you put all required permissions and library in your manifest? do you have a valid key? – ColdFire Aug 21 '12 at 04:06
  • yes sir I believe so... wait I'll show my manifest – philip Aug 21 '12 at 04:10
  • 1
    Are you using your own map api key? Check that once. – Praveenkumar Aug 21 '12 at 04:14
  • your manifest looks fine.. how about your apiKey? this may cause such problem.. btw does the Log give any problem? – ColdFire Aug 21 '12 at 04:15
  • I'm not sure about the api key. I'm using a API key for browser apps, is that correct? – philip Aug 21 '12 at 04:17
  • You will have to take the API KEY again for your Android App. – Haresh Chaudhary Aug 21 '12 at 04:19
  • I'm getting this "couldn't get connection factory client" some "java.io exceptions" and "android_maps_conflict_avoidance.com.googlenav.map" and other System.err that are colored yellow – philip Aug 21 '12 at 04:21
  • 1
    Does this answer your question? [Android Studio - Google map still blank on real Android device on release apk](https://stackoverflow.com/questions/30559602/android-studio-google-map-still-blank-on-real-android-device-on-release-apk) – Sweta Jain Sep 22 '21 at 09:29

4 Answers4

1

you have to generate your own apiKey.. follow this link if you haven't done it yet Obtaining a Google Maps Android API Key

ColdFire
  • 6,764
  • 6
  • 35
  • 51
1

Don't use existing map api key or anything else. You have to generate your own map api key with your md5 fingerprint code. Just have a look at below links -

  1. Android Map api key

  2. maps-api-signup

Have a look at existing answer. And, here is a best example for generating map api key with step-by-step. These may helps you surely.

Community
  • 1
  • 1
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
  • I did all the instruction and was able to obtain the fingerprint but it was not MD5 it was SHA1 – philip Aug 21 '12 at 04:42
1

You will have to generate a MD5 key to get registered for Google Key.
To generate the MD5 Key from your PC,the Steps are :


Open the command prompt and follow the steps

C:\Program Files\Java\<JDK_version_number>\bin>keytool -genkey -v -keystore projectkey.keystore   
                   -alias aliasname -keyalg RSA -keysize 2048 -validity 15000    

  //The Above path should be set Accordingly to your Machine

Enter keystore password: ------------
What is your first and last name?
[Unknown]: ------------
What is the name of your organizational unit?
[Unknown]: ------------
What is the name of your organization?
[Unknown]: ------------
What is the name of your City or Locality?
[Unknown]: ------------
What is the name of your State or Province?
[Unknown]: ------------
What is the two-letter country code for this unit?
[Unknown]: ------------

D:\android-sdk-windows-1.6_r1\tools>keytool -v -list -alias aliasname -keystore projectkey.keystore
Enter keystore password:
aliasname, Dec 7, 2010, PrivateKeyEntry,
Certificate fingerprint (MD5): CA:CF:AA:0E:5A:2B:88:C8:64:F1:FA:F7:29:21:50:FF  

Now,go Here and Register for your Google API key with that MD5 Key.

Haresh Chaudhary
  • 4,390
  • 1
  • 34
  • 57
0

just write down these line on cmd prompt to extract the MD5 fingerprint.

keytool.exe -list -alias androiddebugkey -keystore "C:\android\debug.keystore" -storepass android -keypass android

After getting MD5 fingerprint Copy the MD5 certificate fingerprint and navigate your web browser to: http://code.google.com/android/maps-api-signup.html. Follow the instructions on the page to complete the application and obtain the Google Maps key.

To use the Google Maps in your Android application, you need to modify your AndroidManifest.xml file by adding the element together with the INTERNET permission:

To display the Google Maps in your Android application, modify the main.xml file located in the res/layout folder. You shall use the element to display the Google Maps in your activity. In addition, let's use the element to position the map within the activity:

for example :

<com.google.android.maps.MapView 
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0l4sCTTyRmXTNo7k8DREHvEaLar2UmHGwnhZVHQ"
        />
Nipun Gogia
  • 1,846
  • 1
  • 11
  • 17