2017-07-05 5 views
0

私はそれにGoogleマップの断片で簡単なアプリケーションをしようとしています。私はAndroid-Studioのプリセットから始めました。新しくなったので、ツールバーは表示されますが、マップフラグメントは表示されません。続いて、あなたは私のコードとスタックトレースが表示されます。マップフラグメントが表示されないのはなぜですか?

activity_maps.xmlが

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="1080dp" 
    android:layout_height="1920dp" 
    tools:context=".MapsActivity"> 
    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:map="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="1720dp" 
     tools:context="com.example.testingmapingmarker23.MapsActivity" 
     /> 



    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 

     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
</RelativeLayout> 

MapsActivity.java

package com.example.testingmapingmarker23; 

import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.ListView; 

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; 



import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 



import static com.example.testingmapingmarker23.R.id.map; 

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(map); 
     mapFragment.getMapAsync(this); 

     final Toolbar customToolbar = (Toolbar) findViewById(R.id.toolbar); 



    } 


    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Sydney, Australia. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 
    @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)); 
     mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 

    } 





} 

のAndroidManifest.xml

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

    <!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 
    --> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 



     <meta-data 
      android:name="com.google.android.geo.API_KEY" 
      android:value=" AIz...." /> 

     <activity 
      android:name=".MapsActivity" 
      android:label="@string/title_activity_maps"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

スタックトレース

/com.example.testingmapingmarker23 W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000023/n/armeabi-v7a 
07-05 23:22:08.294 21301-21845/com.example.testingmapingmarker23 W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000023/n/armeabi 
07-05 23:22:08.296 21301-21849/com.example.testingmapingmarker23 W/Adreno-ES20: <core_glEGLImageTargetTexture2DOES:4548>: GL_INVALID_VALUE 
07-05 23:22:08.298 21301-21849/com.example.testingmapingmarker23 W/Adreno-ES20: <core_glEGLImageTargetTexture2DOES:4548>: GL_INVALID_VALUE 
07-05 23:22:08.298 21301-21849/com.example.testingmapingmarker23 E/GLConsumer: [SurfaceTexture-0-21301-0] bindTextureImage: error binding external image: 0x501 
07-05 23:22:08.343 21301-21849/com.example.testingmapingmarker23 W/Adreno-ES20: <core_glEGLImageTargetTexture2DOES:4548>: GL_INVALID_VALUE 
07-05 23:22:08.345 21301-21849/com.example.testingmapingmarker23 W/Adreno-ES20: <core_glEGLImageTargetTexture2DOES:4548>: GL_INVALID_VALUE 

そして、これは何度も繰り返されます。 OnePlus OneをAndroid 6.0.1で使用し、API 23を表示しています。アプリケーションは実行されますが、地図の断片は表示されません。レイアウトの

+0

アンドロイド:layout_height = "1720dp" 'が奇妙に見える –

+0

これは、マップが画面全体であってはならないからです。ツールバーの場所もあるはずです。 – MrHarrison

+0

LinearLayoutを使用...要素のサイズをハードコードする理由はありません –

答えて

0

カスタムツールバーを使用している場合は、より良い NoActionBar にごスタイルを変更します。相対的なレイアウトを使用して

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 

、ツールバー用 、維持

android:layout_alignParentTop="true" 

とそのマップフラグメントのための

android:layout_below="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

これは単に上部に、地図の断片など一部の下にツールバーを配置します。表示されていない地図のための今

あなたはGoogleがアプリでサービス依存関係を再生入れています?

また、権限のすぐ上のマニフェストファイルにこれを追加します。

<permission 
     android:name="your_package_name.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature"/> 

申し訳ありませんが、回答できませんでした。

希望すると助かります!

関連する問題