Akram
Akram

Reputation: 7526

How to place a pushpin on MapView that does not move with the map?

How to place a pushpin in middle of the MapView so that we can move navigate the a location to that pushpin to select that location.

Upvotes: 1

Views: 565

Answers (2)

Stan Kurdziel
Stan Kurdziel

Reputation: 5724

To expand on jeet's Jan 30th answer, here's some layout xml to do the first method - which I believe is easier and will look better and move smoother than the 2nd suggestion.

Pretty simple, but maybe would save someone a few mins:

<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>

Upvotes: 1

jeet
jeet

Reputation: 29199

There are many approaches you can implement to achieve this.

  1. You can add MapView and push pin(image view) to relative layout, and set property of push pin center in parent, on click on push pin calculate mid-point of map, and work accordingly.

  2. Calculate MapView's center point, and add overlay on that point. Override on touch event, and onKeyUp event, recalculate mid point, and redraw overlay.

Upvotes: 3

Related Questions