0

我正在尝试使用 Google Maps Api V2 并遵循Android Google Maps Article中的所有步骤

但在所有步骤之后,代码在我的 glaxy young 上使用 android 2.36 执行,但显示空白地图屏幕

我的主要活动代码是

  protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showmapactivity_layout);
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment 
 = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
map = mySupportMapFragment.getMap();

//map = 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);
}

Maifestfile 代码是

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

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

<permission
    android:name="com.archifiles.pointpakistan.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

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

<uses-permission android:name="com.archifiles.pointpakistan.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" >
    <activity
        android:name="com.archifiles.pointpakistan.SplashScreenActivity"
        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=".MainActivity"></activity>
    <activity android:name=".POIActivity"></activity>
    <activity android:name=".ShowMapActivity"></activity>

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

    <uses-library  
   android:name="com.google.android.maps"  
   android:required="true" /> 

</application>

布局文件代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

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

</RelativeLayout> 

log cat 中没有可用的日志跟踪。

4

2 回答 2

0

其实你用过SupportMapFragment。喜欢

SupportMapFragment gm;

  gm = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap();

所以在xml文件中你也必须像这样使用

      <fragment  
      android:id="@+id/map"
      android:name="com.google.android.gms.maps.SupportMapFragment"
      />

希望它会奏效。

在清单中删除以下行

<uses-library  
 android:name="com.google.android.maps"  
 android:required="true" /> 
于 2013-05-03T08:18:58.693 回答
0

这个问题是由于无效的密钥而发生的,生成一个有效的密钥并将您当前的包名称添加到 hashkey 的末尾。

获取密钥:

In the left navigation bar, click API Access.
In the resulting page, click Create New Android Key....

In the resulting dialog, enter the SHA-1 fingerprint, then a semicolon, then your application's package name. For example:

BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75;com.example.android.mapexample

The Google APIs Console responds by displaying Key for Android apps (with certificates) followed by a forty-character API key, for

例子:

AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0

Copy this key value. You will use it in the next step.

检查这个网址。

https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key
于 2013-05-03T10:27:34.450 回答