【问题标题】:android- How to see the map using maps libandroid-如何使用地图库查看地图
【发布时间】:2011-11-01 21:36:55
【问题描述】:

我实现了显示地图的应用程序。它使用纬度和经度显示特定位置。但它显示一个空的地图。如何查看地图。请任何人都可以帮助我。

code

公共类 mapsdemo 扩展 MapActivity {

MapView mapView;
GeoPoint gp;
MapController mc;

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

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

    List mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
    HelloItemizedOverlay itemizedOverlay = new HelloItemizedOverlay(drawable, this);

    double lat = 17.385044;
    double longi = 78.486671;

    gp = new GeoPoint((int) (lat *1E6),(int) (longi *1E6));
    OverlayItem overlayitem =  new OverlayItem(gp, "Hello", "I'm in Hyd");                                                                      
    itemizedOverlay.addOverlay(overlayitem);        
    mapOverlays.add(itemizedOverlay);

    mc = mapView.getController();
    mc.animateTo(gp);
    mc.setZoom(13);
}

@Override
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:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

 < com.google.android.maps.MapView
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:apiKey="00YCOT71Vu0btHPPlbIR9uvF0-l4mcAVT9_6HMw"   
                 android:id="@+id/mapView"  
                 android:enabled="true"
                 android:clickable="true"        
                 />
< /LinearLayout>

manifeast

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.maps.demo"
      android:versionCode="1"
      android:versionName="1.0">

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

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".mapsdemo"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
            <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>

【问题讨论】:

  • 我发布了 main.xml。请参考
  • map api 密钥是由您的 PC 或任何其他 PC 生成的?
  • 仅限我们的电脑。我使用这个视频教程创建youtube.com/watch?v=vgr4l1nsFdU
  • 每台电脑都是独一无二的吗?我们为单台电脑生成了多少个 api 密钥?
  • 如果您只是使用默认的调试密钥库,那么它在每台 PC 上都会有所不同,除非您明确在计算机之间共享密钥库或将 eclipse 插件设置为使用特定的密钥库。

标签: android maps


【解决方案1】:

这很可能是由签名不匹配引起的。确保您从用于通过 Google 打包您的应用程序的密钥库在 maps API signup page 注册了您的私钥,并确保颁发的密钥在您的 MapView 布局文件中。

【讨论】:

  • 我在答案中链接的 maps api 注册页面显示了用于获取私钥的 MD5 指纹的 keytool 命令。只需确保您使用的是正确的密钥库(如果您使用的是 eclipse android 插件并且没有更改任何默认设置,它将位于主文件夹中的 .android 目录中)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
  • 2011-07-22
  • 1970-01-01
相关资源
最近更新 更多