2014-07-06 1 views
1

Google Maps Api V2로 앱을 만들려고하지만 매번 줌 버튼이있는 빈 화면 만 있습니다. 나는 모든 것이 내 코드에 있다고 생각한다. 나는 필요한 모든 권한을 가지고, 나는 올바르게 열쇠를 가지고있다. 이미 debug.keystore를 다른 하나를 생성하기 위해 Eclipse를 삭제하지만, 여전히 줌 버튼과 동일한 빈 화면이 있습니다. 내 암호가 잘못되어 있으면 누구나 볼 수 있습니까?Google Maps Android API V2가있는 빈지도 만있는 이유는 무엇입니까?

내 매니페스트 :

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

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

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

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

<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" /> 

<!-- Required to show current location --> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

<!-- Required OpenGL ES 2.0. for Maps V2 --> 
<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" > 
    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="****My key here***" /> 
    <meta-data 
     android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 
    <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> 
</application> 

내 레이아웃 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

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

</RelativeLayout> 

내 자바 코드 :

package com.example.meu; 

import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.os.Bundle; 
import android.widget.Toast; 

public class MainActivity extends Activity { 

     // Google Map 
     private GoogleMap googleMap; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     try { 
      // Loading map 
      setContentView(R.layout.activity_main); 
      initilizeMap(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
    } 

} 

/** 
* 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(); 
     } 
    } 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    initilizeMap(); 
} 

나는 이미 많은 것을 읽었지만 아무도 나를 도울 수 없었다.

+0

Try - public 클래스 MainActivity는 extends Activity 대신 FragmentActivity를 확장합니다. –

+0

및 ((SupportMapFragment) getSupportFragmentManager(). findFragmentById (R.id.map)). getMap(); 대신에 (MapFragment) –

+0

먼저, 고마워! 나는이 일을하지만 여전히 일하지 않는다. 그런 다음 minsdk를 8로 변경하고 대상을 20으로 변경하고 내 에뮬레이터 (안드로이드 4.3)에서 마침내 작동하지만 내 장치 (안드로이드 4.1.2)에서 동일한 빈지도가 있습니다. 이제 나는 혼란스러워. – Natan

답변

0

첫째 :지도가 조각 (지도 API V.2는)이기 때문에 당신은 두 번째

public class MainActivity extends Activity { 

public class MainActivity extends FragmentActivity { 

대신 FragmentActivity로 MainActivity를 확장해야합니다 : 조각으로 캐스팅 할 때 지도는 SupportMapFragment 클래스 (안드로이드 버전 사이에 더 나은 cmpatability를 위해)와 getSupportFragmentManager()을 사용하여지도 조각을 찾습니다. 대신 또한

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

((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); 

: 질문 "아스 커"의 의견에 따라 (!?) : 당신은 앱이 아닌 실제 장치에서 에뮬레이터에서 작동하고 있음을 발견하면 , 응용 프로그램을 빌드 할 때 Debug.Keystore를 사용해야합니다.

참고 : 전체 앱에서 이전 버전과 호환되는 지원 라이브러리를 사용하고 있는지 항상 확인하십시오. (물론 여러 Android 버전의 버전을 타겟팅하고 있지만 누구도 자신의 앱을 몇 가지로 제한하는 이유를 이해할 수 없습니다. 버전?) 및 모든 키, 자격증 명, Auths 등이 Google 개발자 콘솔에 올바르게 설정되어 있어야합니다. 후 https://console.developers.google.com/

0

는 Ryno 코찌 저를 제안 무엇을, 응용 프로그램 에뮬레이터에서 작동하지만 장치를 않습니다. 하지만 APK 파일로 내보낼 때 debug.keystore 대신 다른 키 저장소를 사용했기 때문에 앱에서 장치가 작동하지 않습니다. 그 후, 내 응용 프로그램은 마침내 장치 및 에뮬레이터에서 작동합니다. 감사합니다.