2013-10-15 2 views
-1

나는 자습서를 사용하여 Google지도를 테스트하고 있지만지도가 표시되지 않습니다. 그냥 회색 타일. 저를 도우십시오. 나의 프로젝트는 이것 때문에 막혔다.Google지도가 표시되지 않습니다. 회색 타일 만

여기에 내가 다시 시도 편집 된 코드는 다음과 같은 내 코드

입니다. 코드와 logcat 파일을 살펴보십시오.

매니페스트 파일

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.googlemapsv2" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="18" /> 

    <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" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <!-- 
    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" /> 

    <permission 
     android:name="com.example.googlemapsv2.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="com.example.googlemapsv2.permission.MAPS_RECEIVE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.googlemapsv2.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> 

     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="AIzaSyCmYChMyMqZCj5nZl-lykGioJwNGW-hTCA" /> 

    </application> 


</manifest> 

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

     <fragment 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:name="com.google.android.gms.maps.MapFragment" 
      /> 

</RelativeLayout> 

MainActivity.java

package com.example.googlemapsv2; 

import android.os.Bundle; 
import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.view.Menu; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 


public class MainActivity extends Activity { 

    GoogleMap map; 
    @SuppressLint("NewApi") 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
    } 



} 

로그 캣

10-17 19:16:53.750: E/Google Maps Android API(9452): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map. 
10-17 19:16:53.750: E/Google Maps Android API(9452): Ensure that the following correspond to what is in the API Console: Package Name: com.example.googlemapsv2, API Key: AIzaSyCmYChMyMqZCj5nZl-lykGioJwNGW-hTCA, Certificate Fingerprint: 5A6683F0B22028AFBFF49C0EC90FCFA015AA20C6 
10-17 19:16:53.773: I/Google Maps Android API(9452): Failed to contact Google servers. Another attempt will be made when connectivity is established. 
+0

어떻게 그 apikey를 생성 했습니까? 튜토리얼의 튜토리얼을 사용 했습니까? – Marcelo

+0

아니요, Google지도 API V2를 생성했습니다. 사용되지 않는 API가 아닙니다. –

+0

Google지도 V1 클래스를 사용하고 있습니다. 내 대답을 확인하십시오. http://stackoverflow.com/questions/15041200/google-maps-api-key-not-working-v2/15041476#15041476 – Marcelo

답변

2

는 매니페스트 파일에 키를 사용하여 API 키를 변경하고 다음 단계를 수행, 여기를 참조하십시오.

매니페스트 파일 :

<uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="18" /> 

    <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" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.geeklabs.map.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> 

     <meta-data 
    android:name="com.google.android.maps.v2.API_KEY" 
    android:value="replace with your API key"/> 

    </application> 

</manifest> 

MainActivity.java는 :

package com.geeklabs.map; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

} 

activity_main.xml :

<?xml version="1.0" encoding="utf-8"?> 
    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:name="com.google.android.gms.maps.MapFragment"/> 

후이 알려 얻었다.

+0

activity_main의 첫 번째 줄 <조각을 클릭하는 오류를 붙여 - 설명 \t을 자원 \t 경로 \t 위치 \t 유형 예기치 않은 네임 스페이스 접두사 "xmlns"태그 조각에 대해 찾았습니다. \t activity_main.xml \t/GoogleMapsV2/res/layout \t line 11 \t Android Lint 문제 –

+0

k, activity_main.xml에서 이전 코드를 제거하고 게시 한 코드와 함께 배치하십시오. 그리고 프로젝트를 마우스 오른쪽 버튼으로 클릭하여 lint 경고를 무시하십시오. -> Android Tools -> lint 마커를 지우십시오. 도움이 될지도 모릅니다. "인증 실패"위에 게시 된 –

+0

같은 오류가 :( –

0

매니페스트가 올바르게 설정되지 않아지도가 작동하지 않습니다. Android 설명서의 this tutorial 사용자에게 필요한 정확한 권한을 사용 설정해야합니다. 또한 API 키가 잘못된 위치에 있습니다. 조각상이 아니라 당신의 매니 페스트에 들어갑니다. 을하고 google_play_services_lib 프로젝트는 프로젝트의 작업 공간에 존재한다는 것을 확인하십시오

+0

자, 제가 시험해보고 알려 드리겠습니다. –

+0

이 튜토리얼을 따라했지만 activity_main.xml 파일에 오류가 발생했습니다 –

+1

"오류가 발생합니다"라고 말하면 전혀 도움이되지 않습니다. 오류가 무엇인지 알려주십시오. – Codeman

-1

특정 장치에서로드하는 동안 Google지도 버전 2에 문제가 있습니다. 장치를 다시 시작하기 만하면 작동하기 시작합니다.

관련 문제