Java Android:谷歌地图未显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20949052/
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
Android: Google Maps not showing
提问by user43051
I got the SHA1 from Eclipse Windows\Preferences\Android\Build, entered it in the API console in the form of key com.mypackage
, got the API key entered it in the manifest and the map is still not showing.
我从 Eclipse Windows\Preferences\Android\Build 获得 SHA1,以 key 的形式在 API 控制台中com.mypackage
输入它,将 API 密钥输入到清单中,但地图仍未显示。
I tried with the cmd and still not working, it shows the same SHA1 as Eclipse.
我尝试使用 cmd 但仍然无法正常工作,它显示与 Eclipse 相同的 SHA1。
Am I missing something?
我错过了什么吗?
回答by Bosko Mijin
Add this line in manifest file before your activity and inside application tag
在您的活动和应用程序标签内的清单文件中添加这一行
<uses-library android:name="com.google.android.maps" />
That should solve your problem.
那应该可以解决您的问题。
回答by dinesh sharma
回答by Satyaki Mukherjee
There are so many things you should maintain, if you add your Manifest file, then it will be easy for us to give answer. Though I give you my manifest file please follow this and change the package.name only
你要维护的东西太多了,如果你添加你的Manifest文件,那么我们很容易给出答案。虽然我给了你我的清单文件,但请遵循这个并只更改 package.name
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="package.name.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="package.name.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"/>
<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="package.name.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.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="***Your API Key***"/>
</application>
In your XML layout file paste this:
在您的 XML 布局文件中粘贴以下内容:
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tv_location"
class="com.google.android.gms.maps.SupportMapFragment"
/>
Try this and let me know.
试试这个,让我知道。
Add Google play service as a library.
将 Google Play 服务添加为库。
回答by Rahul K R
Put
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-library android:name="com.google.android.maps"/>
in Manifest.xml
回答by Sujit Acharya
In my case google map was not rendering. Only Goolge was displayed below left corner
在我的情况下,谷歌地图没有呈现。左下角只显示谷歌
I have Followed below steps
我已经按照以下步骤
- created again new project in Google api console.
- Passed my SHA1 key then semicolon then your application package name Your_SHA1_Key;Your_APP_PACKAGE_NAME
- You will get one API_KEY
- 在 Google api 控制台中再次创建了新项目。
- 传递我的 SHA1 密钥,然后是分号,然后是您的应用程序包名称 Your_SHA1_Key;Your_APP_PACKAGE_NAME
- 你会得到一个 API_KEY
Then mention below things in your manifest
然后在清单中提及以下内容
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_API_KEY" />
It may help you.
它可能会帮助你。
All the best.
祝一切顺利。
回答by kinsell
Follow the instructions given here. After creating your project in Google Developers Console, select APIs, you will be prompted with a section of Popular APIs, select Google Maps Android API. Press enable API.(the image below is showing the steps in the new version of the console)
按照此处给出的说明进行操作。在 Google Developers Console 中创建您的项目后,选择 APIs,您将看到一个“Popular APIs”部分,选择 Google Maps Android API。按启用 API。(下图显示了新版控制台中的步骤)
If you're still using the old console, enable the API, by selecting Services, then switch the button ON:
如果您仍在使用旧控制台,请通过选择服务启用 API,然后打开按钮:
Note:You don't need to enable the API for the debug version!
注意:您不需要为调试版本启用 API!
Here is nice blogthat will be helpful.
这是一个不错的博客,会有所帮助。
回答by Ese Udom
You may be signing your app with a different certificate other than the one in your debug.keystore file located in your .android folder.
除了位于 .android 文件夹中的 debug.keystore 文件中的证书之外,您可能正在使用不同的证书为您的应用程序签名。
Make sure the SHA1 certificates match i.e the certificate in your credentials are the same with the one you're using to sign your app
确保 SHA1 证书匹配,即您凭据中的证书与您用于签署应用程序的证书相同