Android 地图不显示
我在一块碎片里有一张地图。到目前为止,它的表现是正确的。现在,我看到了谷歌的徽标、+/-按钮和带有正方形的灰色表面(这不是典型的空白背景),但我没有看到地图 logcat持续显示以下内容:Android 地图不显示,android,google-maps,Android,Google Maps,我在一块碎片里有一张地图。到目前为止,它的表现是正确的。现在,我看到了谷歌的徽标、+/-按钮和带有正方形的灰色表面(这不是典型的空白背景),但我没有看到地图 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-3
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="..."/>
请尝试以下方法
/*添加了Bi Dilip*/
我终于找到了解决方案。若您使用私有密钥库来应用API_密钥,那个么就不能用eclipse上载和安装应用程序,为此,您必须使用调试密钥。如果希望使用私有密钥库查看地图,则需要自己将.apk文件上载到设备并安装 如果清单文件中的google map api键设置错误,就会发生这种情况,请检查。@yuvaツ 我补充说code@Karan,我对API密钥有一个问题,我正在使用一个用于调试,我创建了一个新的用于发布。到目前为止,它一直正常工作,所以我不认为这可能是原因。请检查一下:@Karan在那里发布的任何东西都没有解决我的问题
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>