2013-10-30 96 views
1

我創建了一個活動不顯示,我展示了谷歌地圖。我在下面的鏈接中完成了所有這些步驟。Android的谷歌地圖,但在平板電腦

http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/

當我嘗試在三星Galaxy Note 2,我得到這個截圖:

enter image description here

但是,當我嘗試在三星Galaxy Note 10.1,我得到這個(沒有地圖所示,只有變焦按鈕):

enter image description here

這裏是我Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.android.app" 
    android:versionCode="1" 
    android:versionName="1.0" > 
<permission 
    android:name="com.example.googlev2map.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 

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

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

<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="@android:style/Theme.NoTitleBar.Fullscreen" > 
    <activity 
     android:name="com.android.app.SplashScreenLoading" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.android.app.Map" 
     android:label="@string/title_activity_map" > 
    </activity> 

    <!-- Goolge Maps API Key --> 
    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIzaSyAvlLrKpq0Pf-6xzzHqtq-XattJ_zf58pk" /> 
</application> 

</manifest> 

這是我Map.java代碼:

package com.android.tuyap; 

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

import android.os.Bundle; 
import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.graphics.Typeface; 
import android.support.v4.app.FragmentActivity; 
import android.view.Menu; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 

public class Map extends FragmentActivity { 
    // Google Map 
    private GoogleMap googleMap; 

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

     try { 
      // Loading map 
      initilizeMap(); 

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

     double latitude = 41.020133; 
     double longitude = 28.542910; 

     // create marker 
     MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Marker title"); 

     // adding marker 
     googleMap.addMarker(marker); 
     googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude),15)); 
    } 

    private void initilizeMap() { 
     if (googleMap == null) { 
      SupportMapFragment fm = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)); 
      googleMap=fm.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(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     //getMenuInflater().inflate(R.menu.map, menu); 
     return true; 
    } 
    } 

和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:background="@drawable/splash_screen_background" 
     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" > 

     <LinearLayout 
      android:id="@+id/headerLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/main_menu_gradient_header" 
      android:orientation="horizontal" > 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="2" > 

       <ImageView 
        android:id="@+id/backButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:layout_margin="5dp" 
        android:src="@drawable/back_button" /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" > 

       <TextView 
        android:id="@+id/txtSubHeader" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:text="Text Header" 
        android:textSize="@dimen/SubHeaderTextSize" /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="2" > 

       <ImageView 
        android:id="@+id/mainMenuButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:layout_margin="5dp" 
        android:src="@drawable/main_menu_button" /> 

      </RelativeLayout> 
     </LinearLayout> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/headerLayout" 
      android:orientation="vertical" 
      android:weightSum="2" > 

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

     </RelativeLayout> 

    </RelativeLayout> 

爲什麼我不能顯示在的Galaxy Note 10.1平板電腦的地圖嗎?

+1

嘗試卸載應用程序,並重新安裝,可能發生在你的清單文件已經改變,在設備上直接測試出與卸載以前安裝的應用。而且這次也嘗試清理你的項目。 – Maulik

+0

是的!卸載並重新安裝程序後問題解決。非常感謝! –

+1

你可以從堆棧中刪除你的問題在流動或簡單地接受我的答案,使用戶未來可以理解的理由或答案。 – Maulik

回答

2

Try to uninstall the app and install it again,它可能是當你在manifest文件發生了變化,與出卸載以前安裝的應用程序直接在設備上測試情況。而且這次也嘗試清理你的項目。這將是隻發生在你的清單文件或任何XML文件將不會反映要麼你忘了清理項目或卸載以前的項目中,設備是不是工作或不工作的谷歌地圖的情況。

相關問題