0

I am trying to create my first Google Maps in Android using an emulator in Eclipse with no success. All I get for the map is a gray tiled screen that I can zoom but there is no map there. Below is my AndroidManifest file:

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

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

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
    <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" >
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="com.example.herb2.Herb2Activity"
            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>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="my key is not shown here" />

</manifest>

Below is my layout file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <TextView
        android:id="@+id/latitude_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Latitude: " />

    <TextView
        android:id="@+id/longitude_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Longitude: " />

    <com.google.android.maps.MapView
        android:id="@+id/mapvw"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:apiKey="my key is not shown here"
        android:clickable="true"
        android:enabled="true" />

</LinearLayout>

Finally below is my java source:

public class Herb2Activity extends MapActivity {

    private TextView latitudeView;
    private TextView longitudeView;
    private LocationManager locationManager;
    private MapController mapController;
    private MapView mapView;
    private GeoPoint point;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_herb2);
        latitudeView = (TextView) findViewById(R.id.latitude_view);
        longitudeView = (TextView) findViewById(R.id.longitude_view);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        mapView = (MapView) findViewById(R.id.mapvw);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(true);
        mapController = mapView.getController();
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                3600, 1000, new LocationListener() {

                    public void onProviderDisabled(String provider) {
                    }

                    public void onProviderEnabled(String provider) {
                    }

                    public void onStatusChanged(String provider, int status,
                            Bundle extras) {
                    }

                    public void onLocationChanged(Location loc) {
                        if (loc != null) {
                            int lt = (int) (loc.getLatitude());
                            int lg = (int) (loc.getLongitude());
                            latitudeView.setText("Latitude is: "
                                    + String.valueOf(lt));
                            longitudeView.setText("Longitude is: "
                                    + String.valueOf(lg));
                            int latit = (int) (loc.getLatitude() * 1E6);
                            int longit = (int) (loc.getLongitude() * 1E6);
                            point = new GeoPoint(latit, longit);
                            mapController.animateTo(point);
                            mapController.setZoom(15);
                        }
                    }
                });
    }

    @Override
    protected boolean isRouteDisplayed() {
        return true;
    }

    @Override
    protected boolean isLocationDisplayed() {
        return false;
    }
}

I am suspecting it may have something to do with my API key which I generated from Google. I provided the SHA1 certificate fingerprints to generate my key. I added at the end of the key my package name which is com.example.herb2 as shown above. I also made sure I was using a Google API device as my emulator. I assume the MD5 fingerprint is used for production. I will appreciate any help on why my map shows nothing but gray.

4

1 回答 1

1

您是否查看过 Android 中的 Google 地图签名的 api 密钥错误

很可能是您使用的是签名密钥而不是调试密钥。

于 2013-03-06T04:06:47.140 回答