地图和地图工具栏未显示

时间:2017-05-29 17:38:24

标签: android google-maps

我想在我的详细活动中显示小地图。我想显示工具栏,所以当我点击方向时,它会打开google方向并制作路线。但我的地图不会显示,工具栏也不会显示。 enter image description here

activity_event_detail.xml

      <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_event_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.project.pmi.pmi.EventDetailActivity">
    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content" android:id="@+id/toolbar"
            android:background="@color/colorPrimaryDark"
            android:theme="@style/AppTheme.AppBarOverlay"
            android:popupTheme="@style/AppTheme.PopupOverlay"
            />
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" android:background="@color/colorPrimary">
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"
                android:layout_marginLeft="5dp" android:layout_marginRight="5dp">

                <fragment
                    android:id="@+id/mapFragment"
                    class="com.google.android.gms.maps.SupportMapFragment"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"/>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/color_divider"
                    android:layout_marginTop="10dp"
                    android:id="@+id/view1"/>

            </LinearLayout>
        </ScrollView>
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

EventDetailActivity.java

public class EventDetailActivity extends AppCompatActivity implements OnMapReadyCallback{
TextView tvTitle, tvDate, tvTime, tvDesc, tvLoc;
ImageView imgEventDet;
double longitude = 0, latitude = 0;

public SupportMapFragment mapFragment;
private GoogleMap mMap;

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

    Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(myToolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle("Event");


    mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment));
    mapFragment.getMapAsync(this);

}

@Override
public boolean onSupportNavigateUp() {
    onBackPressed();
    return true;
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.addMarker(new MarkerOptions().position(new LatLng(latitude,longitude)).title("Marker")
            .icon(BitmapDescriptorFactory.defaultMarker()));
    mMap.getUiSettings().setZoomControlsEnabled(false);
    mMap.getUiSettings().setMapToolbarEnabled(true);
    mMap.getUiSettings().setAllGesturesEnabled(false);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 16));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 16));
}
}
  

编译'com.google.android.gms:play-services-maps:10.2.0'

     

编译'com.google.android.gms:play-services-location:10.2.0'

0 个答案:

没有答案