2016-11-27 4 views
0

マイレイアウトを中心にされていないように見えますが。アンドロイドグーグルマップのマーカーが

アクティビティコード:期待とマーカーが地図の中心に示されているよう

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_edit_location); 
    ... 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 
} 

@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 

    mMap.getUiSettings().setZoomControlsEnabled(true); 

    LatLng point = new LatLng(mService.getLocation().getLatitude(), mService.getLocation().getLongitude()); 
    mMap.addMarker(new MarkerOptions().position(point).title(mService.getName())); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(point)); 
    mMap.animateCamera(CameraUpdateFactory.zoomTo(16)); 
} 

今ではすべての場合は動作します。マーカーが地図の中心にいない表示され

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar"> 
    </include> 

    <AutoCompleteTextView 
     android:id="@+id/edit_location_input" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/edit_location_input_hint"/> 

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

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

</LinearLayout> 

(実際に私は必要があります。このようなAutoCompleteTextViewの下

しかし、私は、余分なTextViewを追加します(ID edit_location_inputとビューの下を参照)マップをズームして移動してマーカーを表示することができます)。近くにあるように見えます。

私はTextView

<TextView 
     android:id="@+id/edit_location_result" 
     android:layout_width="match_parent" 
     android:layout_height="40dp"/> 

に一定の幅を設定すると予想されるようにマーカーが中央に表示されます。

いくつかのビューがマップに影響し、それを修正する理由は何ですか?

答えて

0

問題はレイアウト上ではなく、マーカーの中央に配置するカメラの動き/アニメーションにあります。あなたのpointにカメラを移動しようと、不要マップゾーンのレベル16までのズームが生じ重ねることができる6つのが、これら2つのイベントが拡大することをアニメーション化します

mMap.moveCamera(CameraUpdateFactory.newLatLng(point)); 
mMap.animateCamera(CameraUpdateFactory.zoomTo(16)); 

マップを行う

。あなたはまだあなたがMapUtilsからCameraUpdateAnimatorを使用することができ、カメラを移動し、それをアニメーション化する必要がある場合は

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, 16)); 

:最も簡単な解決策は一つだけの動きでカメラを更新している問題を解決するために

(私のプロジェクト):

CameraUpdateAnimator animator = new CameraUpdateAnimator(mMap, null); 

animator.add(CameraUpdateFactory.newLatLng(point), false, 100); 
animator.add(CameraUpdateFactory.zoomTo(16), true, 1000); 

animator.execute(); 
関連する問題