【问题标题】:Android MapFragment API v2 empty map with just zoom controls仅具有缩放控件的 Android MapFragment API v2 空地图
【发布时间】:2014-11-10 22:41:17
【问题描述】:

我正在尝试实现 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 已在服务上启用。

据我所知,我一切正常,但仍在加载空白地图。

【问题讨论】:

  • 将您的最小 SDK 更改为 12。或使用 SupportMapFrament
  • 编辑:只是改变 SDK 工作,我只是不耐烦它加载哈哈
  • MapFragment 适用于 api 12 及以上版本。再次交叉检查您的密钥,您是否正确引用了库项目
  • 如果你想把它作为答案发布,我可以接受这个问题
  • 请检查发布的答案。您可以安全地将 min sdk 更改为 12 或更高版本。因为没有根据仪表板运行 api 11 的设备

标签: android google-maps google-maps-android-api-2


【解决方案1】:

您应该将 min sdk 更改为 12 或更高版本。

对于 api 12 及以上版本使用 MapFragment,对于 api 11 及以下版本使用 SupportMapFramgent

http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html

看看这个

 http://developer.android.com/about/dashboards/index.html

我觉得最好把你的 min sdk 改成 12

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 2012-11-24
    相关资源
    最近更新 更多