安卓谷歌地图无法加载
Posted
技术标签:
【中文标题】安卓谷歌地图无法加载【英文标题】:android google map not load 【发布时间】:2015-08-04 14:54:48 【问题描述】:我的问题是当应用程序连接到 Google Map APi V2 时地图未加载 它连接没有任何错误但地图未加载 缩放按钮出现了,但是.....
请帮帮我
如果你有任何 Simale 代码供我使用,请给我 谢谢
它是 manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<permission
android:name="com.example.maps.permission.MAP_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.maps.permission.MAP_RECEIVE"/>
<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.googel.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="0x0002000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android: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.geo.API_KEY"
android:value="[edited]"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
这是 Xml 文件
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_
android:layout_
/>
这是 MainActivity
package com.example.maps;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class MainActivity extends FragmentActivity
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
【问题讨论】:
可能是api Key的问题,看下面的答案 我以前试过,但没用 您是否在 google apis 控制台上启用了 de Google Maps Android API v2? 您是否在您的设备/模拟器中安装了 GooglePlay 服务? 是的,我启用了 Google Maps Android API v2 【参考方案1】:您确定元数据名称是“com.google.android.geo.API_KEY”而不是“com.google.android.maps.v2.API_KEY ”。请检查一次。
【讨论】:
我以前试过,但没用 您使用的是代理连接后面的网络吗?你能在设备上打开谷歌地图应用吗? 是的,我可以打开谷歌地图【参考方案2】:确保在您的 manifest.xml 中使用它
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_KEY_HERE" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
您使用 com.google.android.geo.API_KEY,而不是 com.google.android.maps.v2.API_KEY
更新
您的 MainActivity 似乎没有加载地图。一个简单的例子如下所示:
private GoogleMap mMap;
if (mMap == null)
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null)
Location locationdefault = new Location("NewYork");
locationdefault.setLatitude(41.145495);
locationdefault.setLongitude(−73.994901);
【讨论】:
您使用的是 Android Studio 还是 Eclipse? 你应该考虑使用Android Studio,它现在是Android的官方IDE。我认为 Eclipse 无法识别 2 个元数据标签。 我想要,但 Android Studio 还是测试版 我使用的是 1.2 版。它经常更新,绝对稳定,而不是测试版。它比 Eclipse 更容易。你不能再在 Eclipse 中使用 Google Play Services 功能而不会出现问题! 好的,谢谢。我不知道稳定版是否可用以上是关于安卓谷歌地图无法加载的主要内容,如果未能解决你的问题,请参考以下文章
无法将谷歌静态地图加载到jquery mobile中的div中
谷歌地图跨平台网址在“应用内导航”后无法在 Android 上加载路线