谷歌地图选项Android

谷歌地图选项Android,android,google-maps,Android,Google Maps,我想在Android应用程序中为Google地图片段添加属性。我找对地图了吗?我将如何实现下面的示例?下面是源代码 示例(我想添加类似的内容) fragment1\u layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_par

我想在Android应用程序中为Google地图片段添加属性。我找对地图了吗?我将如何实现下面的示例?下面是源代码

示例(我想添加类似的内容)

fragment1\u layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#D70B0D"
    android:orientation="vertical" >

     <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="5dp"
        android:text="@string/textView6"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FFFFFF"
        android:textStyle="bold" />

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:layout_margin="5dp"/>

    <Button
        android:id="@+id/btnRespond"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:text="@string/btnRespond"
        android:layout_gravity="center"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:background="@drawable/button_animation"
        android:padding="5dp"/>


</LinearLayout>

onCreateView
方法中将
fragment
强制转换为
MapFragment
,然后像这样调用map async

MapFragment mapFragment = (MapFragment) getFragmentManager()
            .findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
摘自谷歌地图文档


然后,在加载映射时,将自动调用
OnMapReady

获取此错误=“无法从片段强制转换为MapFragment”尝试将
getFragmentManager()
更改为
getSupportFragmentManager()
new error=“getSupportFragmentManager()方法对于Fragment1类型未定义”请先尝试此操作,将其替换为
getActivity().getSupportFragmentManager()
,如果不起作用,请检查我认为正在尝试执行相同操作的对象。是否因为我使用onCreateView而不是onCreate,因为当我尝试通过id“txt1=(textview)getView().findViewById(R.id.txt1);”而不是“txt1=(TextView)findViewById(R.id.txt1);“因为我在findViewById部分出错
package ie.itsligo.medication;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

public class Fragment1 extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment1_layout, container, false);

        Fragment map = (Fragment) getFragmentManager().findFragmentById(R.id.map);

        Button btn = (Button) view.findViewById(R.id.btnRespond);

        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "You Are Now Active! Swipe Left For Individual Details & Medical Information", Toast.LENGTH_LONG).show();
            }
        });

        return view; 
    }
}
MapFragment mapFragment = (MapFragment) getFragmentManager()
            .findFragmentById(R.id.map);
mapFragment.getMapAsync(this);