java 谷歌地图 Android 仅显示白屏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14237390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google maps Android only white screen is shown
提问by Damian SIlvera
I did al procedure to add google maps api but i am getting this errors. Sorry for bad language.
我做了所有程序来添加谷歌地图 api,但我收到了这个错误。对不起,语言不好。
09 12:20:55.359: W/dalvikvm(5918): Unable to resolve superclass of Lmaps/a/du; (406)
01-09 12:20:55.359: W/dalvikvm(5918): Link of class 'Lmaps/a/du;' failed
01-09 12:20:55.359: W/dalvikvm(5918): Unable to resolve superclass of Lmaps/a/ej; (2358)
01-09 12:20:55.359: W/dalvikvm(5918): Link of class 'Lmaps/a/ej;' failed
01-09 12:20:55.359: W/dalvikvm(5918): Unable to resolve superclass of Lmaps/j/k; (2374)
01-09 12:20:55.359: W/dalvikvm(5918): Link of class 'Lmaps/j/k;' failed
01-09 12:20:55.359: E/dalvikvm(5918): Could not find class 'maps.j.k', referenced from method maps.y.ae.a
01-09 12:20:55.359: W/dalvikvm(5918): VFY: unable to resolve new-instance 3566 (Lmaps/j/k;) in Lmaps/y/ae;
Here its the manifest.xml
这里是 manifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.comparto.piso.permission.MAPS_RECEIVE" />
<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" />
<permission
android:name="com.comparto.piso.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<application
........ >
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key" />
......
.....
In java code i extends FragmentActivity and here its the onCreate code
在java代码中,我扩展了FragmentActivity,这里是onCreate代码
GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getApplicationContext());
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
if (map != null) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
here its the layout xml
这里是布局xml
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="300px"
class="com.google.android.gms.maps.SupportMapFragment" />
回答by Joe
All the "Unable to resolve superclass xxxx" and "Link of class xxxx failed" from Dalvik in the logcat is normal if your device is not on the same API level as the one used by the Google Maps library.
如果您的设备与 Google 地图库使用的 API 级别不同,那么 logcat 中来自 Dalvik 的所有“无法解析超类 xxxx”和“xxxx 类链接失败”都是正常的。
You should check whether you are getting an authorization failure instead by using this command:
您应该使用以下命令检查是否出现授权失败:
adb logcat | grep Maps
If you see something like this:
如果你看到这样的东西:
E/Google Maps Android API(): Authorization failure.
Then it would mean that you are not supplying the correct API key in your manifest. Check again in your Google API Console(in the API Accesssection) whether you have added the correct fingerprint and package name pair as described in the guide.
那么这意味着您没有在清单中提供正确的 API 密钥。在您的Google API 控制台(在API 访问部分)中再次检查您是否已按照指南中的说明添加了正确的指纹和包名称对。
回答by iagreen
That error message usally occurs when running on a device that does not have Google Play APIs available. You call isGooglePlayServicesAvailable()
, but you are not checking the return value. You should check to make sure it returns ConnectionResult.SUCCESS
before proceeding. In the case of some other error codes, you can have them prompted to upgrade/install via getErrorDialog()
, like --
在没有可用的 Google Play API 的设备上运行时,通常会出现该错误消息。您调用isGooglePlayServicesAvailable()
,但您没有检查返回值。ConnectionResult.SUCCESS
在继续之前,您应该检查以确保它返回。在出现其他一些错误代码的情况下,您可以通过 提示他们升级/安装getErrorDialog()
,例如-
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
switch (resultCode) {
case ConnectionResult.SUCCESS: // proceed
break;
case ConnectionResult.SERVICE_MISSING:
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
case ConnectionResult.SERVICE_DISABLED:
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1);
dialog.show();
}
According to Google, Google Play services API's require 'physical development device', so they are not officially supported on the emulators. So, if you are running on an emulator, it is almost certain you are missing the required services. People report getting it to work in emulators, but I have not tried myself. You can view than answers in this post, if you want to look at installing Google Play on an emulator.
根据 Google 的说法,Google Play 服务 API 需要“物理开发设备”,因此模拟器并未正式支持它们。因此,如果您在模拟器上运行,几乎可以肯定您缺少所需的服务。人们报告说让它在模拟器中工作,但我自己没有尝试过。如果您想查看在模拟器上安装 Google Play,您可以查看这篇文章中的答案。
回答by Hitesh Sahu
回答by BBonDoo
If you use "class="com.google.android.gms.maps.SupportMapFragment" in your layout xml, you are now using your android:minSdkVersion under Android 3.0 or lower in your manifest.xml.
如果您在布局 xml 中使用“class="com.google.android.gms.maps.SupportMapFragment”,则您现在在 manifest.xml 中使用的是 Android 3.0 或更低版本下的 android:minSdkVersion。
And then see my linked site below, which is helpful for you to understand what you should install and set before running the Google maps on your device. This link is very easy and you will get what you want to do in order to display google maps on your device.
然后在下面查看我的链接站点,这有助于您了解在设备上运行 Google 地图之前应该安装和设置的内容。此链接非常简单,您将获得想要执行的操作,以便在您的设备上显示谷歌地图。
回答by nobjta_9x_tq
Maybe your SHA1 key of your eclipse was changed (EX: You maybe deleted .android folder in home folder of windows) so it is the reason why it authentication error. You must delete your key and create new key with new SHA1 of eclipse.
也许你的 eclipse 的 SHA1 密钥被更改了(例如:你可能删除了 windows 主文件夹中的 .android 文件夹),所以这就是身份验证错误的原因。您必须删除您的密钥并使用 eclipse 的新 SHA1 创建新密钥。
Regen new key in here and reload this page in some minutes, it will update new key: https://console.developers.google.com/project/watchful-net-796/apiui/credential
在此处重新生成新密钥并在几分钟后重新加载此页面,它将更新新密钥:https: //console.developers.google.com/project/watchful-net-796/apiui/credential
Remember! After all, you must copy new key to manifest and rebuild your project. Good luck!
记住!毕竟,您必须复制新密钥以显示和重建您的项目。祝你好运!
回答by Jawad Zeb
you have missing api key
你缺少 api 密钥
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key" />
enter api_key in value parameter
在 value 参数中输入 api_key
And google playService
version is also missing . Add
而且google playService
版本也不见了。添加
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
to manifest
inside <application
tag
到manifest
内部<application
标签