2014-12-13 49 views
1

我是一位使用Google Maps v2的新Android开发人员。Android Google Maps v2 - 将标记保留在地图的中心

我只需要让用户拖动地图,但初始标记不应随之移动。

这是我布局

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

这是我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)); 

     } 

    } 

} 

是否有谷歌地图的任何方法,我可以使用?

+0

相关http://stackoverflow.com/questions/19557575/move-the-map-by-keeping-the-marker-in-center&http://stackoverflow.com/questions/16783087/how-do- I-保持-A-谷歌地图-标记在最中心的最-MAP-无滞后 – 2015-11-05 12:59:50

回答

0

尝试用这个..而不是你的代码

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

使用此代码将“保留标记在地图的中心”

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

你可以模拟它。不要使用真实的Marker,而应在MapView的顶部的RelativeLayout的中心。

相关问题