简体   繁体   English

如何在活动中使用mapView?

[英]How use the mapView in activity?

在我的应用程序中,可以使用其他布局主XML中包含两个视图,其中第一个视图仅具有简单的文本视图,第二个视图中具有地图视图。在我的主XML文件中,当我单击第一个按钮以显示时有两个按钮带有文本视图的第一个视图,当我单击第二个按钮时,我想隐藏第一个视图并以地图视图显示第二个视图。我不知道如何在主要活动中显示地图视图。有谁知道请帮助我解决这个问题。

Firstly tell what version of google maps do you use v1 - https://developers.google.com/maps/documentation/android/v1/ v2 - https://developers.google.com/maps/documentation/android/start 首先说出您使用的v1版本的Google地图-https: //developers.google.com/maps/documentation/android/v1/ v2- https://developers.google.com/maps/documentation/android/start

Usually what you need to do is to put you two layouts inside FrameLayout and show/hide one of them when you click on particular button. 通常,您需要做的是在FrameLayout中放置两个布局,并在单击特定按钮时显示/隐藏其中之一。 But to be more specific we need to see your code. 但更具体地说,我们需要查看您的代码。

1) MapView is used by GoogleMapsV1. 1)MapView由GoogleMapsV1使用。 But it needs an api key provided by google for individual developers upon registration. 但它需要由Google为注册的个人开发者提供的api密钥。

Unfortunately, which is closed by google and you have to use GoogleMapV2 with new V2 key. 不幸的是,它已被google关闭,您必须将GoogleMapV2与新的V2密钥一起使用。

Also, workout with fragments because, here we are using Fragment or SupportFragment. 另外,还需要对片段进行锻炼,因为在这里我们使用Fragment或SupportFragment。

2) You can use a FrameLayout inside which your two overlapped views with id's. 2)您可以使用一个FrameLayout,在其中两个带有id的重叠视图。 So that you can show or hide views at same position as you need. 这样您就可以根据需要在相同位置显示或隐藏视图。

Please try to use bellow code. 请尝试使用以下代码。

<LinearLayout
    android:id="@+id/buttonLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button2" />
</LinearLayout>

<ViewFlipper
    android:id="@+id/viewFliper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/buttonLayout" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:apiKey="your map key map_key"
        android:clickable="true"
        android:enabled="true"
        android:focusable="true"
        android:focusableInTouchMode="true" />
</ViewFlipper>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM