【问题标题】:MapView google maps api V2 looks blank only display grid with +/- buttonMapView google maps api V2 看起来只有空白,显示网格带有 +/- 按钮
【发布时间】:2014-02-26 15:01:49
【问题描述】:

我完成所有步骤,我将 google-play-sevices 添加到我的项目中,我做所有事情。我不知道有什么问题。我使用调试证书指纹创建我的 api 密钥,使用 Eclipse windows 中的SHA1指纹>偏好>安卓;我正在使用 lg E400 con android 2.3.6

MainActivity:

import android.os.Bundle;
import android.app.Activity;


import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;

public class MainActivity extends Activity {
  GoogleMap map;
  MapView m;
  com.google.android.gms.maps.Projection projection;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     m=(MapView) findViewById(R.id.mapview);
    m.onCreate(savedInstanceState);
    map = m.getMap();
    if (map != null) {
        // The Map is verified. It is now safe to manipulate the map.

    }else{
        // check if google play service in the device is not available or out-dated.
        GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        // nothing anymore, cuz android will take care of the rest (to remind user to update google play service).
    }

    try{map.getUiSettings().setMyLocationButtonEnabled(false);
    map.setMyLocationEnabled(true);
    }catch(Exception ex){ex.printStackTrace();}

    MapsInitializer.initialize(this);

}
@Override
public void onResume() {

    super.onResume();
    m.onResume();
}
@Override
public void onDestroy() {
    super.onDestroy();
    m.onDestroy();
}
@Override
public void onLowMemory() {

   super.onLowMemory();
   m.onLowMemory();
}
 @Override
public void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);
     m.onSaveInstanceState(outState);
  }
}

布局:

<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" >


<com.google.android.gms.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</RelativeLayout>

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.voicesee"

android:versionCode="1"
android:versionName="1.0" >

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

<permission
    android:name="com.example.voicesee.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.voicesee.permission.MAPS_RECEIVE" />
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"  />                                                   
<!-- The following two permissions are not required to use
 Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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" >
   <meta-data
   android:name="com.google.android.gms.version"
   android:value="@integer/google_play_services_version" />


    <activity
        android:name="com.example.voicesee.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>

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


</application>

谢谢你的帮助!!

【问题讨论】:

    标签: android google-maps android-maps-v2


    【解决方案1】:

    我遇到了类似的问题,我的问题是因为我选择了错误的调试密钥库。我正在使用 ubuntu 机器。由于我以 root 身份打开 eclipse,因此 eclipse 中的默认密钥库位于我的根文件夹(/root/.android/.android/debug.keystore)中,而我正在使用我的用户文件夹中的调试密钥库创建 api 密钥。我添加了一个指向已回答问题的链接: Google Maps V2 shows blank screen on android 2.2

    【讨论】:

      【解决方案2】:

      你确定:你的项目在Google Console开启

      谷歌地图 Android API v2

      【讨论】:

      • 是的!我确定,我做到了!
      【解决方案3】:

      首先,我不明白您为什么在将地图放置在Acitivity 中时使用MapView,因为这样做会更难显示地图,Google 的documentation 声明:

      如果您正在寻找针对早期平台的更简单的地图显示方法,请使用 MapFragment(或 SupportMapFragment)。

      其次,如果你已经这样做了,那么你在实现它时犯了一些错误,因为你放置了:

      MapsInitializer.initialize(this);
      

      方法在错误的地方,正如documentation 所说:

      如果需要在获取地图之前使用功能,请使用此类初始化 Google Maps Android API。必须调用,因为BitmapDescriptorFactory、CameraUpdateFactory等类需要初始化。

      【讨论】:

        【解决方案4】:

        您需要使用片段来封装您的地图,并且片段仅受 Android API 级别 11 及更高版本(3.0 及更高版本)支持。这可能是您的问题的原因。

        here 所述,您需要为您的 API 版本使用 SupportMapFragment。

        Here 是学习如何使用它的链接。

        如果这不起作用,我猜是 API 密钥。之前我们遇到过加载网格和缩放按钮而不是地图的情况,关键是罪魁祸首。我将逐步完成here 的步骤,以确保您已正确完成所有操作(包括使用 google play 服务)

        【讨论】:

          【解决方案5】:

          在我的代码中,我用 supportMapfragment 更改了 mapview,我删除了我以前的 debug.keytool 并重建了它,然后我删除了我的旧 apikey 并创建了一个新密钥。看来我的问题是与 google play 服务的连接,因为它可以工作添加 GooglePlayServicesUtil.isGooglePlayServicesAvailable() 并在调用 setContentview() 之前验证与 google play 服务的连接

          【讨论】:

            【解决方案6】:

            检查一下清单中的 api 密钥和应用程序的 SHA 密钥。您可以通过访问 console.developers.google.com 创建新的密钥。

            要查看 SHA 密钥日食,请转到 --> windows>preferences>在左侧面板中选择android>点击build

            查看 SHA 密钥 android studio 看这个链接How to get the SHA-1 fingerprint certificate in Android Studio for debug mode?

            【讨论】:

              猜你喜欢
              • 2019-10-18
              • 2013-02-14
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2012-11-25
              • 1970-01-01
              相关资源
              最近更新 更多