我试图实现 MapFragment,但我遇到了一个问题,即显示 mapfragment 但它是空的,我只看到缩放控件。
这是我的代码。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<permission
android:name="com.example.myapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.myapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myapp.ActivityMain"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity><activity
android:name=".ActivityCentres"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".ActivityCentrePage"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".ActivityViewTimetable"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".ActivityOpeningTimes"
android:label="@string/app_name">
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="myAPIKEY" />
</application>
</manifest>
.java
LatLng HAMBURG = new LatLng(53.558, 9.927);
LatLng KIEL = new LatLng(53.551, 9.993);
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
if (map !=null){
Log.d("FUApp", "Map isnt null");
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)));
}
else
{
Log.d("FUApp", "map is null");
}
我通过运行此命令获得了我的 API 密钥
keytool -list -v -alias androiddebugkey -keystore C:/Users/Tom/.android/debug.keystore -storepass android -keypass android
并复制 SHA-1 并将其放入 google API 控制台“MySHA1;com.example.myapp”
我已经检查了服务上启用了 Google Maps Android V2。
据我所知,我一切正常,但它仍在加载一张空白地图。