2016-03-22 11 views
0

私は開発中のアプリ内でmapviewを取得するのに苦労しています。 GoogleコンソールでAPIキーを正常に生成しました。マニフェストにアクセス許可を追加していくつかの失敗についてはlogcatを確認しましたが、何もしません。ここでmapview V2を表示することができません

はレイアウトです:ここでは

<LinearLayout 
    android:id="@+id/main_box_container2" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="5dp" 
    android:layout_marginTop="5dp" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/box_container2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:minWidth="450dp" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/geo_map_title" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="@string/distribuzione_title" 
      android:textSize="28sp" 
      android:textStyle="bold" /> 

     <com.google.android.gms.maps.MapView 
      android:id="@+id/map_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

     </com.google.android.gms.maps.MapView> 

    </LinearLayout> 
</LinearLayout> 

が明らかである:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="it.previnet.mobile.dashboard.credem" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 

    <permission 
     android:name="it.previnet.mobile.dashboard.credem.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <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="it.previnet.mobile.dashboard.credem.permission.MAPS_RECEIVE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/logo_credemvita" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".DashboardActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="landscape" > 
      <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="AIzaSyDfFnshaZgWuun842Z3wzGN4gqp2dj98ew" /> 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
    </application> 

</manifest> 

そして、ここでコード:

protected void initMap(View geo) { 
    // Gets the MapView from the XML layout and creates it 
    mapView = (MapView) geo.findViewById(R.id.map_view); 
    mapView.onCreate(savedInstanceState); 
    mapView.getMapAsync(this); 
} 

@Override 
public void onMapReady(GoogleMap map) { 
    map.getUiSettings().setMyLocationButtonEnabled(true); 
    map.setMyLocationEnabled(true); 

    // Needs to call MapsInitializer before doing any CameraUpdateFactory calls 
    try { 
     MapsInitializer.initialize(this.getActivity()); 
    } catch (Exception e) { 
     Log.e(TAG, e.getMessage(), e); 
    } 

    // Updates the location and zoom of the MapView 
    LatLng latLng = new LatLng(43.1, -87.9); 
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10); 
    map.addMarker(new MarkerOptions().position(new LatLng(43.1, -87.9)).title("Marker")); 
    map.animateCamera(cameraUpdate); 
} 

答えて

0

私はこの問題は、マップではなかった、見つかりました上のテキストビュー。 layout_heightをwrap_contentに変更しました。私はMapViewを見ることができます。

1

なぜすべてのパラメータの高さを設定するのですか?match_parent ???

<LinearLayout 
android:id="@+id/main_box_container2" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:layout_marginLeft="5dp" 
android:layout_marginTop="5dp" 
android:orientation="horizontal" > 

<LinearLayout 
    android:id="@+id/box_container2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:minWidth="450dp" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/geo_map_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/distribuzione_title" 
     android:textSize="28sp" 
     android:textStyle="bold" /> 

    <com.google.android.gms.maps.MapView 
     android:id="@+id/map_view" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

    </com.google.android.gms.maps.MapView> 

</LinearLayout> 

私はこのコードを示唆します
関連する問題