我创建了一个地图活动。该应用程序运行时没有崩溃,但是当我打开活动时,它仅显示google徽标,但未加载google map。因此,我检查了运行时错误,它显示了以下错误。
错误
V / PhoneWindow:DecorView setVisiblity:可见性= 4,父级= ViewRoot {615057f com.example.kularathna.gpstracker / com.example.kularathna.gpstracker.ticketBooking,ident = 4},此= DecorView @ dce7bbe [ticketBooking] E / Google Maps Android API:授权失败。请参阅https://developers.google.com/maps/documentation/android-api/start,了解如何正确设置地图。 E / Google Maps Android API:在Google Developer Console(https://console.developers.google.com)中 确保已启用“ Google Maps Android API v2”。 确保存在以下Android密钥: API密钥:AIzaSyBWfu7WllVlnzgXuNAWhU_Ca0U3EC2BDvc Android应用程序(;):6B:C7:FB:B3:C6:FE:D3:22:DA:14:AE:27:B6:88:FA:13:ED:82:63:BA; com.example。 kularathna.gpstracker W / DynamiteModule:找不到com.google.android.gms.google证书的本地模块描述符类。 I / DynamiteModule:考虑本地模块com.google.android.gms.googlecertificates:0和远程模块com.google.android.gms.googlecertificates:4 com.google.android.gms.googlecertificates的选定远程版本,版本> = 4 W / zygote64:由于无法识别的类加载器而跳过重复的类检查 D /曲面:Surface :: disconnect(this = 0x7efc6d4000,api = 1) D / WindowClient:从mView中删除:android.widget.LinearLayout {e39f9c9 V.E ...... ...... ID 0,0-162,75},此= android.view.WindowManagerGlobal@7707265 应用已终止。
以下错误显示为蓝色
W / DynamiteModule:找不到com.google.android.gms.google证书的本地模块描述符类。
W / zygote64:由于无法识别类加载器而跳过重复的类检查
以下错误显示为棕色
Xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".map">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/fragmentMap"/>
</LinearLayout>
</RelativeLayout>
map.java文件
package com.example.kularathna.gpstracker;
import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
public class map extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap mGoogleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
if (googleServicesAvailable()){
Toast.makeText(this,"Perfect",Toast.LENGTH_LONG).show();
initMap();
}else {
// No Google Map Layout
}
}
private void initMap() {
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.fragmentMap);
mapFragment.getMapAsync(this);
}
public boolean googleServicesAvailable(){
GoogleApiAvailability api = GoogleApiAvailability.getInstance();
int isAvailable = api.isGooglePlayServicesAvailable(this);
if (isAvailable == ConnectionResult.SUCCESS){
return true;
}else if (api.isUserResolvableError(isAvailable)){
Dialog dialog = api.getErrorDialog(this,isAvailable,0);
dialog.show();
}else {
Toast.makeText(this,"Can't connect to play services",Toast.LENGTH_LONG).show();
}
return false;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
goToLocationZoom(39.008224,-76.8984527,15);
}
private void goToLocation(double longitude, double latitude) {
LatLng latLng = new LatLng (longitude,latitude);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng (latLng);
mGoogleMap.moveCamera (cameraUpdate);
}
private void goToLocationZoom(double longitude, double latitude, float zoom) {
LatLng latLng = new LatLng (longitude,latitude);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, zoom);
mGoogleMap.moveCamera (cameraUpdate);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kularathna.gpstracker">
<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"/>
<permission android:name="com.example.kularathna.gpstracker.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.kularathna.gpstracker.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permissions.READ_GSERVICES"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ticketBooking" />
<activity android:name=".registration" />
<activity android:name=".arrive" />
<activity android:name=".home" />
<activity android:name=".reserveSeats" />
<activity android:name=".seatSelection" />
<activity android:name=".map"></activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBWfu7WllVlnzgXuNAWhU_Ca0U3EC2BDvc"/>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
</application>
</manifest>