我在片段中有一个Map。直到现在,它显示正确。现在,我看到Google徽标,+ / - 按钮和带正方形的灰色表面(它不是典型的空白背景),但我看不到地图。
logcat连续显示:
31 11:47:21.413: D/REQUEST(30479): Connection opened to:https://clients4.google.com/glm/mmap/api
10-31 11:47:21.413: D/REQUEST(30479): Open Connection
10-31 11:47:22.294: D/REQUEST(30479): DRD(42): 62|147|7|108
10-31 11:47:22.294: D/REQUEST(30479): Close
10-31 11:47:22.294: D/REQUEST(30479): Error processing: com.google.maps.api.android.lib6.b.d@43ba8a58 not retrying
10-31 11:47:22.304: D/REQUEST(30479): Retrying: com.google.maps.api.android.lib6.c.au@436cc688
10-31 11:47:22.304: D/REQUEST(30479): Retrying: com.google.maps.api.android.lib6.b.v@43900930
10-31 11:47:22.324: D/REQUEST(30479): Retrying: com.google.maps.api.android.lib6.gmm6.m.af@43375668
10-31 11:47:34.246: D/REQUEST(30479): Connection opened to:https://clients4.google.com/glm/mmap/api
10-31 11:47:34.246: D/REQUEST(30479): Open Connection
10-31 11:47:35.277: D/REQUEST(30479): DRD(43): 62|147|7|108
10-31 11:47:35.277: D/REQUEST(30479): Close
编辑 - 代码添加:
private void checkMap() {
if (mMap == null) {
/*Try to obtain the map from the SupportMapFragment*/
mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
/*Check if we were successful in obtaining the map.*/
if (mMap != null) {
initMap();
}
}
}
private void initMap() {
/*Get location*/
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
/*Set criteria*/
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String provider = locationManager.getBestProvider(criteria, true);
/*Get last known location if exists*/
defaultLocation = locationManager.getLastKnownLocation(provider);
/*If last known location doesn't exist request a single update*/
if (defaultLocation == null) {
locationManager.requestSingleUpdate(criteria, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
defaultLocation = location;
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}, getActivity().getMainLooper());
}
/*Move camera*/
if (defaultLocation != null) {
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(defaultLocation.getLatitude(), defaultLocation.getLongitude()), 5));
}
}
清单:
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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"/>
<!-- 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"/>
<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="..."/>
答案 0 :(得分:2)
最后,我得到了一个解决方案。如果您使用私有密钥库来应用API_KEY,则无法使用eclipse上载和安装应用程序,因此,您必须使用调试密钥。如果您想使用私钥库查看地图,则需要自行将.apk文件上传到您的设备并进行安装。
答案 1 :(得分:1)
首先检查生成的API密钥是否正确且IT是否有效API CONSOLE
添加签名许可。
添加gsf的权限
检查SDK最低版本和最高版本
如果您在模拟器上运行,那么您需要从cmd pormt安装这两个apk文件。 下载链接...
1)https://www.dropbox.com/s/ccnuqmsxdtb75xl/com.android.vending.apk
Open the AVD
Execute this in the terminal / cmd
adb -e install com.google.android.gms.apk
adb -e install com.android.vending.apk
adb install com.google.android.apps.maps-1.apk
adb install com.google.android.gms-2.apk
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dilip.googlemapsv2"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.dilip.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="20" />
<uses-permission android:name="com.dilip.googlemapsv2.permission.MAPS_RECEIVE" />
<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"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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=".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>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your API Generated Key" /> /* Added Bi Dilip */
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>