它显示“服务器上的身份验证失败”错误。 应用程序运行没有崩溃,但 map 是空白的。下面我粘贴了我项目的 logcat 和 MainActivity 类。
这是我项目的MainActivity
static final LatLng TP = new LatLng(17.385044, 78.486671);
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
/*
* try { if (googleMap == null) { googleMap = ((MapFragment)
* getFragmentManager() .findFragmentById(R.id.map)).getMap(); }
* googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
* googleMap.addMarker(new MarkerOptions().position(
* TP).title("TP")); } catch (Exception e) {
* e.printStackTrace(); }
*/
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
initilizeMap();
}
/* function to load map. If map is not created it will create it for you */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
}
## Manifest ##
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cell.track.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="22" />
<permission
android:name="com.example.googlemaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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-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>
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Google MAP API key -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyA4cNBwKoRxmpW0qhMF8B_jBDpkkHaaSsQ" />
</application>
</manifest>
这是日志:
01-05 11:34:22.841: E/b(24238): Authentication failed on the server.
01-05 11:34:22.841: E/Google Maps Android API(24238): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
01-05 11:34:22.851: E/Google Maps Android API(24238): In the Google Developer Console (https://console.developers.google.com)
01-05 11:34:22.851: E/Google Maps Android API(24238): Ensure that the "Google Maps Android API v2" is enabled.
01-05 11:34:22.851: E/Google Maps Android API(24238): Ensure that the following Android Key exists:
01-05 11:34:22.851: E/Google Maps Android API(24238): API Key: AIzaSyA4cNBwKoRxmpW0qhMF8B_jBDpkkHaaSsQ
01-05 11:34:22.851: E/Google Maps Android API(24238): Android Application (<cert_fingerprint>;<package_name>): 90:A8:E0:F0:90:2F:93:73:C6:16:F0:10:B7:D8:2B:8A:24:08:48:7E;com.cell.track.activity
最佳答案
请确保您已将 map API key 添加到您的 list 中。 如果您已正确创建您的 api key ,那么请确保您已从开发人员控制台启用了 google maps api。 我创建了一个场景,其中一切正常,但未启用。显示与您相同的错误。希望对您有所帮助。
关于android - 应用程序正在运行但 MAP 是空白的我正在使用 google map api 来定位某个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34604689/