【问题标题】:Display Map v2 in popup Window not display in android?在弹出窗口中显示地图 v2 不在 android 中显示?
【发布时间】:2016-11-04 16:06:59
【问题描述】:

我想打开弹出窗口,我使用地图 v2 在弹出窗口中显示地图 v2 但未显示 这里我放了我的 xml 布局和活动类

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="100dp"
        android:text="Button" />

</RelativeLayout>

popupstellodetailpage.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popuplayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:orientation="vertical" >

        <Button
            android:id="@+id/buttoncancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel"
            android:layout_gravity="right"
             />

          <fragment
                    android:id="@+id/popupmapview"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="10dp"
                    class="com.google.android.gms.maps.SupportMapFragment" />



</LinearLayout>

MapActivity.java

public class MainActivity extends  FragmentActivity {


     PopupWindow pw;
     GoogleMap map;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button button= (Button)findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                initiatePopupWindow();
            }
        });

    }


    private void initiatePopupWindow() 
    {
        try 
        {

            //We need to get the instance of the LayoutInflater, use the context of this activity
            LayoutInflater inflater = (LayoutInflater) MainActivity.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //Inflate the view from a predefined XML layout
            View layout = inflater.inflate(R.layout.popupstellodetailpage,
                    (ViewGroup) findViewById(R.id.popuplayout));

            // create a 300px width and 470px height PopupWindow
            pw = new PopupWindow(layout, 300, 470, true);

            // display the popup in the center
            pw.showAtLocation(layout, Gravity.CENTER, 0, 0);


            map= ((SupportMapFragment) getSupportFragmentManager()
                     .findFragmentById(R.id.popupmapview)).getMap(); 


            Button buttoncancel=(Button)layout.findViewById(R.id.buttoncancel);
            buttoncancel.setOnClickListener(new OnClickListener() 
            {   
                @Override
                public void onClick(View v) 
                {
                     pw.dismiss();
                }

            });

        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }


    }
}

【问题讨论】:

    标签: android popup google-maps-android-api-2


    【解决方案1】:

    这可能会帮助您Check Here 在这里检查所有您需要显示地图的可能性是完全填充或不输入AndroidManifest.xml

    <permission
            android:name="your.Activity.permission.MAPS_RECEIVE"
            android:protectionLevel="signature" />
    
        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true" />
        <uses-permission android:name="your.Activity.permission.MAPS_RECEIVE" />
    
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_CORSE_LOCATION" />
    
    <meta-data    
       android:name="com.google.android.maps.v2.API_KEY"    
       android:value="your_api_key"/>
    

    【讨论】:

    • 一切都是正确的,但问题不是在弹出窗口中显示,而是在我直接在主类中使用时显示
    • 检查你的 mainClass 如果没有得到告诉我会尽力帮助你
    【解决方案2】:

    他们只是我发现的两个愚蠢的问题..你只需改变这个片段

                    <fragment
                    android:id="@+id/popupmapview"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="10dp"
                    class="com.google.android.gms.maps.SupportMapFragment" />
    

    到这个..

                    <fragment
                    android:id="@+id/popupmapview"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="10dp"
                    class="com.google.android.gms.maps.MapFragment" />
    

    并在方法 [initiatePopupWindow] 中更改一行

    map= ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.popupmapview)).getMap(); 
    

    到这个..

    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.popupmapview)).getMap();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-24
      • 2013-01-06
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      相关资源
      最近更新 更多