简体   繁体   English

Android Google Maps v2 - 将标记保留在地图的中心

[英]Android Google Maps v2 - Keep marker in the center of map

I'm a new Android developer working with Google Maps v2 right now. 我现在是一名使用Google Maps v2的新Android开发人员。

I just need to let the user drag the map but the initial marker shouldn't move with it. 我只需要让用户拖动地图,但初始标记不应随之移动。

This is my layout : 这是我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginTop="20dp"
        android:gravity="top|center_horizontal"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/edtDirection"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_buscar"
            android:lines="1"
            android:maxLines="1"
            android:padding="5dp" />

        <Button
            android:id="@+id/btnSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/btn_buscar" />
    </LinearLayout>

</RelativeLayout>

And this is my MapActivity.java , which displays the map: 这是我的MapActivity.java ,它显示地图:

public class MapaActivity extends Activity {

    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_mapa);

        if (map == null) {
            map = ((MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map)).getMap();

        map.addMarker(new MarkerOptions().position(new LatLng(-12.0000, -77.0000)).title("Origin"));

        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-12.0000, -77.0000), 14));

        }

    }

}

Is there any method of Google Maps that I can use? 我可以使用谷歌地图的任何方法吗?

You can simulate it. 你可以模拟它。 Instead of using a real Marker , center an ImageView on top of the MapView in a RelativeLayout . 而不是使用真正的Marker ,将ImageView置于RelativeLayout中的MapView之上。

Try with this.. Instead of your code 试试这个..而不是你的代码

//map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-12.0000, -77.0000), 14));

Use this code it will 'Keep marker in the center of map' 使用此代码将“将标记保留在地图中心”

        map.animateCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(LatitudeValue, LongitudeValue ), 14));

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

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