使用标记android将MapActivity调用到MainActivity

时间:2018-12-16 17:47:09

标签: android dictionary fragment

我有一个MapActivity(Android默认)和一个MainActivity。我在MainActivity调用包含这样的包含项的MapActivity:

    <include
    android:id="@+id/mapa"
    layout="@layout/activity_maps"/>

它显示了地图,但没有显示任何人知道的标记?在MapActivity中,我有这个:

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(R.id.map);
    mapFragment.getMapAsync(this);

}

@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));
}

谢谢!

1 个答案:

答案 0 :(得分:0)

仅使用此“请勿呼叫”包含布局,否则将无法正常工作

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    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="match_parent"
    tools:context="com.example.mapwithmarker.MapsMarkerActivity" />