GoogleMap v2没有出现在设备上

时间:2013-03-07 04:16:42

标签: android maps

我制作此示例http://mobisys.in/blog/2012/12/google-rolls-out-android-maps-api-v2/,但未在我的设备中显示地图

这是我的AndroidManifest.xml

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

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="15"/>
<permission
    android:name="com.control_guard.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<uses-permission android:name="com.control_guard.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE" />
<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:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Inicio"
        android:label="@string/title_activity_inicio"
        android:theme="@android:style/Theme.Holo.NoActionBar" 
        android:uiOptions="splitActionBarWhenNarrow">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="Login"
        android:theme="@android:style/Theme.Holo.NoActionBar" >
    </activity>
    <activity android:name="MenuControlGuard" >
    </activity>
    <activity android:name="MenuPrincipal" >
    </activity>
    <activity android:name="Asistencia" 
        android:theme="@android:color/holo_blue_dark">
    </activity>
    <activity android:name="ListaPersonal"
        android:theme="@android:color/holo_blue_dark" >
    </activity>
    <activity
        android:name=".DatosPersonal"
        android:label="@string/title_activity_datos_personal" >
    </activity>
    <activity
        android:name=".ListaClientes"
        android:label="@string/title_activity_lista__clientes" 
        android:theme="@android:color/holo_blue_dark">
    </activity>
    <activity
        android:name=".DatosCliente"
        android:label="@string/title_activity_datos_cliente" >
    </activity>
    <activity
        android:name=".MenuReportes"
        android:label="@string/title_activity_menu_reportes" >
    </activity>
    <activity
        android:name=".NuevoReporte"
        android:label="@string/title_activity_nuevo_reporte" >
    </activity>
    <activity
        android:name=".Lista_Reportes"
        android:label="@string/title_activity_lista__reportes"
        android:theme="@android:color/holo_blue_dark" >
    </activity>
    <activity
        android:name=".EditarReporte"
        android:label="@string/title_activity_editar_reporte" >
    </activity>
    <activity
        android:name=".MenuPrincipalOperaciones"
        android:label="@string/title_activity_menu_principal_operaciones" >
    </activity>
    <activity
        android:name=".VerReportes"
        android:label="@string/title_activity_ver_reportes" >
    </activity>
    <activity
        android:name=".ListaSupervisor"
        android:label="@string/title_activity_lista_supervisor"
        android:theme="@android:color/holo_blue_dark" >
    </activity>
    <activity
        android:name=".Mapa"
        android:label="@string/title_activity_mapa" >
    </activity>
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAUvGf-KcrLy4ptevrE5LRK9XCVuYf7vOE" />
</application>

`

我的.xml是

   <fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />`

这是我的.java

package com.control_guard;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class Mapa extends Activity  {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapa);

    final LatLng HAMBURG = new LatLng(53.558, 9.927);
     final LatLng KIEL = new LatLng(53.551, 9.993);
    final GoogleMap map;

      map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
          .getMap();
      Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
          .title("Hamburg"));
      Marker kiel = map.addMarker(new MarkerOptions()
          .position(KIEL)
          .title("Kiel")
          .snippet("Kiel is cool")
          .icon(BitmapDescriptorFactory
              .fromResource(R.drawable.ic_launcher)));

      // Move the camera instantly to hamburg with a zoom of 15.
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

      // Zoom in, animating the camera.
      map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.mapa, menu);
    return true;
}`

我需要帮助解决这个问题,我在代码中找不到错误。

3 个答案:

答案 0 :(得分:1)

你需要一个api密钥,你的清单中你的是空的:

    <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="API-KEY" />

关注this

答案 1 :(得分:0)

您是否完成了文档中提到的所有步骤。如果没有,只需经历一次......只需几个简单的步骤..你将准备好去,他们真的很好

这是指向它的链接。

https://developers.google.com/maps/documentation/android/start

如果问题仍然存在,那么再次提出问题..

答案 2 :(得分:0)

您需要一个API密钥才能在您的应用中显示谷歌地图。请访问此站点并创建API密钥并将API密钥放入您的Android清单文件中。        https://developers.google.com/maps/documentation/android/v1/mapkey