【问题标题】:Runtime errors occurred when creating map activity in android在android中创建地图活动时发生运行时错误
【发布时间】:2019-05-13 08:27:21
【问题描述】:

我创建了一个地图活动。该应用程序正在运行而没有崩溃,但是当我打开活动时,它只显示谷歌徽标,但未加载谷歌地图。因此我检查了运行时错误,它显示以下错误。

错误

V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = ViewRoot{615057f com.example.kularathna.gpstracker/com.example.kularathna.gpstracker.ticketBooking,ident = 4}, this = DecorView@dce7bbe[ticketBooking] E/Google Maps Android API:授权失败。请参阅https://developers.google.com/maps/documentation/android-api/start 了解如何正确设置地图。 E/Google 地图 Android API:在 Google 开发者控制台中 (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.googlecertificates 的本地模块描述符类。 I/DynamiteModule:考虑本地模块 com.google.android.gms.googlecertificates:0 和远程模块 com.google.android.gms.googlecertificates:4 com.google.android.gms.googlecertificates 的选定远程版本,版本 >= 4 W/zygote64:由于无法识别的类加载器而跳过重复类检查 D/Surface:Surface::disconnect(this=0x7efc6d4000,api=1) D/WindowClient:从 mViews 中删除:android.widget.LinearLayout{e39f9c9 V.E...... ......ID 0,0-162,75},this = android.view.WindowManagerGlobal@7707265 应用程序终止。

以下错误显示为蓝色

  • W/DynamiteModule:com.google.android.gms.googlecertificates 的本地模块描述符类未找到。

  • W/zygote64:由于类加载器无法识别而跳过重复类检查

以下错误显示为棕色

  • E/Google Maps Android API:授权失败。请参阅https://developers.google.com/maps/documentation/android-api/start 了解如何正确设置地图。 E/Google 地图 Android API:在 Google 开发者控制台中 (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

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>

ma​​p.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>
API Key screen shot

API key screen shot

【问题讨论】:

  • 我不明白这个程序有什么问题
  • 请帮我解决这个问题
  • 如果你刚刚创建了 API 密钥,稍等片刻,它最终会显示出来
  • 我昨天创建的。
  • 您创建的api密钥不正确。

标签: javascript android


【解决方案1】:

在 google 控制台中使用 api 密钥注册的 SHA 密钥是否与您生成 APK 的机器的 SHA 密钥相同。尝试从控制台移除 SHA 密钥的限制并运行应用程序

【讨论】:

    【解决方案2】:

    同样的问题发生在我身上,我通过启用解决了

    Android 版地图 SDK

    启用 API 如下图,

    还要确保为您的应用程序生成 API 密钥,其包名称如下图所示,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-16
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多