android谷歌地图认证失败

时间:2015-12-29 08:30:52

标签: android google-maps-api-3

我正在尝试在另一个片段中使用谷歌地图片段。我已经生成了api密钥,但是我收到以下错误

> 12-29 13:42:40.218 7993-8796/com.example.sabudaniel61.ktdc E/b:
> Authentication failed on the server. 12-29 13:42:40.218
> 7993-8796/com.example.sabudaniel61.ktdc E/Google Maps Android API:
> Authorization failure.  Please see
> https://developers.google.com/maps/documentation/android/start for how
> to correctly set up the map. 12-29 13:42:40.218
> 7993-8796/com.example.sabudaniel61.ktdc E/Google Maps Android API: In
> the Google Developer Console (https://console.developers.google.com)
> 12-29 13:42:40.218 7993-8796/com.example.sabudaniel61.ktdc
> E/Google Maps Android API: Ensure that the "Google Maps Android API
> v2" is enabled. 12-29 13:42:40.218
> 7993-8796/com.example.sabudaniel61.ktdc E/Google Maps Android API:
> Ensure that the following Android Key exists: 12-29 13:42:40.218
> 7993-8796/com.example.sabudaniel61.ktdc E/Google Maps Android API:
>   API Key: AIzaSyAE82Dh6TCU-HY2mR0BMs9YYYRfM47dJ-w 12-29 13:42:40.218
> 7993-8796/com.example.sabudaniel61.ktdc E/Google Maps Android API:
>   Android Application (<cert_fingerprint>;<package_name>):
> BE:A2:B6:1F:2C:64:C3:C5:7E:E5:3B:7B:6E:82:10:13:9B:50:88:F9;com.example.sabudaniel61.ktdc

以下是我使用谷歌地图的片段

MascotFragment.java:

package com.example.sabudaniel61.ktdc;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;


public class
        MascotFragment extends Fragment implements OnMapReadyCallback {
            private View v;int imgarr[];private Context context; private GoogleMap mMap;


         @Nullable
         @Override
         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
             v=inflater.inflate(R.layout.mascotlayout,container,false);
             SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
                     .findFragmentById(R.id.map);
             mapFragment.getMapAsync(this);


             ViewPager viewPager = (ViewPager) v.findViewById(R.id.vpfragment);
             Bundle bundle=new Bundle();

            ImagePagerAdapter pagerAdapter=new ImagePagerAdapter(v.getContext(),getArguments().getInt("position"));
            viewPager.setAdapter(pagerAdapter);
            viewPager.setPageTransformer(true,new ParallaxPageTransformer());


        videos();
        return v;
    }
    void videos(){
        ImageView imageView=(ImageView) v.findViewById(R.id.mascotvideo1);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(getActivity(),VideoActivity.class);
                startActivity(i);

            }
        });
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

    }
}

mascotlayout.xml: 我在mascotlayout中包含了以下片段

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="250dp" android:id="@+id/map"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_below="@+id/location"
        tools:context="com.example.sabudaniel61.ktdc.MascotFragment"
        android:name="com.google.android.gms.maps.SupportMapFragment" />

googleapikey:

<resources>
    <!--
    TODO: Before you run your application, you need a Google Maps API key.

    To get one, follow this link, follow the directions and press "Create" at the end:

https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=80:D4:72:21:65:03:ED:E7:D5:A2:AC:E7:66:80:A8:F3:14:FB:17:D5%3Bcom.example.sabudaniel61.ktdc

    You can also add your credentials to an existing key, using this line:
    80:D4:72:21:65:03:ED:E7:D5:A2:AC:E7:66:80:A8:F3:14:FB:17:D5;com.example.sabudaniel61.ktdc

    Once you have your key (it starts with "AIza"), replace the "google_maps_key"
    string in this file.
    -->
    <string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
        AIzaSyAE82Dh6TCU-HY2mR0BMs9YYYRfM47dJ-w
    </string>
</resources>

的AndroidManifest.xml:   - &GT;

<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 ACCESS_COARSE/FINE_LOCATION 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.geo.API_KEY"
            android:value="@string/google_maps_key" />

的build.gradle:

compile 'com.google.android.gms:play-services:8.3.0'

0 个答案:

没有答案