0

我正在尝试开发具有两个屏幕的 android 应用程序,在第二个中我希望显示谷歌地图...我在所有可以找到的地方阅读了有关这个问题的所有内容,我做了所有步骤来获取 API 密钥,我编辑了 Manifest xml 文件,第二个屏幕 xml 文件(我想要谷歌地图)...提供 API 密钥,我在前面提到的 xml 文件中设置它,允许使用互联网等...并且仍然..问题仍然存在。如果有人知道可能是什么问题,请回答!

这是我写的一些代码: Manifest(xml) 文件:

<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.androidgui.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>
   <activity android:name=".Mapa"
android:label="@string/screen2Title">
  <meta-data
   android:name="com.google.android.maps.v2.API_KEY"
   android:value="API_KEY"/>
   </activity>


</application>

我希望谷歌地图显示在屏幕的 xml 文件中:

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

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

屏幕的Java文件:

   package com.example.androidgui;
   import android.app.Activity;
   import android.os.Bundle;
   import com.google.android.maps.MapActivity;
   import com.google.android.maps.MapView;

    public class Mapa extends MapActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondscreen);
MapView mapview = (MapView) findViewById(R.id.mapview);
mapview.setBuiltInZoomControls(true);
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
   }
4

1 回答 1

0

您正在尝试使用已弃用的 Google Maps Android API v1 并将其与 Google Maps Android API v2 密钥混合使用。

从 v2 开始最简单的方法是删除与地图相关的所有代码,并在此处按照说明进行操作:https ://developers.google.com/maps/documentation/android/start

于 2013-06-18T20:41:27.500 回答