简体   繁体   English

Android Google 地图 API 无法与 debug.keystore 一起使用

[英]Android Google Maps API not working with debug.keystore

I am attempting to create a MapView application following the tutorial from the Android website here .我正在尝试按照 Android 网站教程创建 MapView 应用程序。 I have got everything set up and the map displays but with empty tiles!我已经设置好所有东西,map 显示,但瓷砖是空的!

The API key I'm using is generated from the debug.keystore located in "C:\Users\Pete\.android" and all of the correct permissions are set up in the manifest.我正在使用的 API 密钥是从位于“C:\Users\Pete\.android”中的 debug.keystore 生成的,并且所有正确的权限都在清单中设置。 The maps library is also in the manifest but it still doesn't work.地图库也在清单中,但它仍然不起作用。 I have tried creating a new debug keystore and placed it in the same folder (obviously also generating a new API key) and still no luck.我尝试创建一个新的调试密钥库并将其放在同一个文件夹中(显然还生成了一个新的 API 密钥),但仍然没有运气。

(30/05/2011) Edit: (30/05/2011) 编辑:

Manifest.xml清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.stringerapps.testing.gps"
        android:versionCode="1"
        android:versionName="1.0">
   <uses-sdk android:minSdkVersion="8" />

   <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Home"
              android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
        </activity>

     <!-- import the library com.google.android.maps!!! -->
     <uses-library android:name="com.google.android.maps" />

     <!-- permissions -->
     <uses-permission
         android:name="android.permission.INTERNET">
     </uses-permission>
     <uses-permission
         android:name="android.permission.ACCESS_FINE_LOCATION">
     </uses-permission>

    </application>

</manifest>

layout.xml布局.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/mainlayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="api-key-here-omitted"/>

</RelativeLayout>

Home.xml主页.xml

package com.stringerapps.testing.gps;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.LinearLayout;

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

public class Home extends MapActivity {

LinearLayout linearLayout;
MapView mapView;

List<Overlay> mapOverlays;
Drawable drawable;
MyItemizedOverlay itemizedOverlay;

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

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

    mapOverlays = mapView.getOverlays();
    drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    itemizedOverlay = new MyItemizedOverlay(drawable);

    GeoPoint point = new GeoPoint(19240000, -99120000);
    OverlayItem overlayitem = new OverlayItem(point, "", "");

    GeoPoint point2 = new GeoPoint(35410000, 139460000);
    OverlayItem overlayitem2 = new OverlayItem(point2, "", "");

    itemizedOverlay.addOverlay(overlayitem);
    itemizedOverlay.addOverlay(overlayitem2);
    mapOverlays.add(itemizedOverlay);
}

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

The <uses-permission> tags need to go outside of the <application> tag. <uses-permission>标签需要 go 在<application>标签之外。

See: Google map displaying only blank tiles android请参阅: Google map 仅显示空白图块 android

Your manifest file needs some reshuffling:您的清单文件需要重新洗牌:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.stringerapps.testing.gps"
        android:versionCode="1"
        android:versionName="1.0">
   <uses-sdk android:minSdkVersion="8" />

     <!-- permissions -->
     <uses-permission
         android:name="android.permission.INTERNET">
     </uses-permission>
     <uses-permission
         android:name="android.permission.ACCESS_FINE_LOCATION">
     </uses-permission>
   <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Home"
              android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
        </activity>

     <!-- import the library com.google.android.maps!!! -->
     <uses-library android:name="com.google.android.maps" />


    </application>
</manifest>

Try that and I'll look through your other files to see if I can find anything else.试试看,我会查看您的其他文件,看看是否还能找到其他文件。

Important thing here is always to use proper fingerprint (keystore for fingerprint).这里重要的是始终使用正确的指纹(指纹密钥库)。 I had the same problem before:).我之前遇到过同样的问题:)。 If you are debugging your application, use debug fingerprint as is described here and you will be safe.如果您正在调试您的应用程序,请使用此处描述的调试指纹,您将是安全的。 Then if you will decide to publish application then you will create own fingerprint for public use.然后,如果您决定发布应用程序,那么您将创建自己的指纹供公众使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM