如何在不随地图移动的MapView上放置图钉?

时间:2012-01-30 11:53:17

标签: android android-mapview

如何将图钉放置在MapView的中间,以便我们可以将位置导航到该图钉以选择该位置。

2 个答案:

答案 0 :(得分:3)

您可以通过许多方法来实现这一目标。

  1. 您可以将MapView和推针(图像视图)添加到相对布局,并在父级中设置推针中心的属性,点击推针计算地图的中点,并相应地工作。

  2. 计算MapView的中心点,并在该点上添加叠加层。覆盖触摸事件和onKeyUp事件,重新计算中点和重绘覆盖。

答案 1 :(得分:1)

为了扩展jeet的1月30日答案,这里有一些布局xml来做第一种方法 - 我认为这种方法更容易,看起来更好,比第二种建议更顺畅。

非常简单,但也许可以节省几分钟的时间:

<RelativeLayout ...>

    <com.google.android.maps.MapView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        ... />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/map_location_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/map_location_pin" />
    </RelativeLayout>
</RelativeLayout>