0

私はセットアップGoogleマップと移動する車のマーカーを持っているGoogleマップアプリケーションに取り組んでいます。私はAPIから緯度と経度を取得しており、定期的に(25秒ごとに)Googleマップ上のマーカーを更新しています。定期的に移動するマーカーと一緒にGoogleマップを移動する方法

  When updating marker I am unable to move the google map along with the marker. How to move the google map along with the periodically moving marker. 

何か助けが私にとって大きな助けになるはずです。

答えて

1

次のコードスニペットは、カメラを移動するための一般的な方法のいくつかを説明しますDocumentation for the Android Google Maps API

EDITに基づいて

private static final LatLng SYDNEY = new LatLng(-33.88,151.21); 
private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1); 

private GoogleMap map; 
... 

// Obtain the map from a MapFragment or MapView. 

// Move the camera instantly to Sydney with a zoom of 15. 
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 15)); 

// Zoom in, animating the camera. 
map.animateCamera(CameraUpdateFactory.zoomIn()); 

// Zoom out to zoom level 10, animating with a duration of 2 seconds. 
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); 

// Construct a CameraPosition focusing on Mountain View and animate the camera to that position. 
CameraPosition cameraPosition = new CameraPosition.Builder() 
       .target(MOUNTAIN_VIEW)      // Sets the center of the map to Mountain View 
       .zoom(17)                   // Sets the zoom 
       .bearing(90)                // Sets the orientation of the camera to east 
       .tilt(30)                   // Sets the tilt of the camera to 30 degrees 
       .build();                   // Creates a CameraPosition from the builder 

map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 

私はGoogleマップに関するUdacity上のいくつかの興味深いのコースを見つけました:

+1

このコードはGeorge.SPに感謝します。それは働いている。 –

2

ので、マーカーの位置の変化に伴ってマップを移動するために、あなたは次のようになめらか操作を行うことができます。

public void onLocationChanged(Location loc) { 
    //some marker movements here... 

    CameraPosition currentPlace = new CameraPosition.Builder() 
      .target(new LatLng(loc.getLatitude(), loc.getLongitude()) 
      .tilt(0f) 
      .zoom(18) 
      .build(); 

    map.animateCamera(CameraUpdateFactory.newCameraPosition(currentPlace), 200, null); 
} 

は勿論、あなたがGoogleマップオブジェクトにアクセスする必要があります。

+0

おかげRybzor。それは役に立ちました。 –

関連する問題