2013-06-12 56 views
8

我使用MapView(新API v2)和屬於路線的點列表。他們非常接近。我的問題是,如果我做動畫步驟調用在地圖上平滑地動畫攝影機路徑

 mMapInstance.animateCamera(CameraUpdateFactory.newLatLng(mNextPosition),ms, null); 

的攝影師的行爲就像一個勇敢的螞蚱,和盤子和在exaggerately,並在這一過程A1中的滑動緩存得到@ ## @#@#!

什麼是使路徑動畫並獲得統一的滾動體驗的最佳方法?速度不是問題,我會使用低速度,我對平滑度感興趣...

如果我可以模擬我用手指做的路徑,我會更加高興。因爲地圖的表現非常好並且有很多緩存周圍的瓷磚。但任何嘗試以編程方式移動地圖結果在大膽的動畫,白色屏幕,重新加載瓷磚...

在此先感謝!

回答

1

嗯,我希望有人提供一個更好的答案,但通過我做的很多實驗,我無法使用animateCamera獲得像樣的平滑滾動。

無論只有靠近點的Lat/Lng變化,攝影師都不停地做出令人印象深刻的起飛和着陸。

我取得了有限的「EL-小氣鬼」動畫的成功有以下程序:

private void animateTo(double lat, double lon, double zoom, double bearing, double tilt, final int milliseconds) { 

     if (mMapInstance==null) return; 
     mMapInstance.setMapType(paramMapMode); 
     mCurrentPosition=new LatLng(lat,lon); 

     // animate camera jumps too much 
     // so we set the camera instantly to the next point 

     mMapInstance.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(mCurrentPosition,(float)zoom, (float)tilt, (float)bearing))); 

     // give Android a break so it can load tiles. If I start the animation 
     // without pause, no tile loading is done 

     mMap.postDelayed(new Runnable(){ 
      @Override 
      public void run() { 
       // keeping numbers small you get a nice scrolling effect 
       mMapInstance.animateCamera(CameraUpdateFactory.scrollBy(250-(float)Math.random()*500-250, 250-(float)Math.random()*500),milliseconds,null); 

      }},500); 

    } 

這個程序,調用在10000S毫秒值,變爲一個點,則使得天橋動畫隨機方向保持該死的變焦tranquilo。由於像素值非常小,因此可能會緩存所有內容。

任何人都有更好的解決方案?嘗試注入觸摸事件以模擬「觸摸」的投擲是否合理或可能?

+4

你不能調用'postDelayed()'上MMAP! –

4

我發現使用可選的回調函數作爲最終參數來顯示遞歸解決方案可以提供平滑的動畫。此代碼放大,改變全景旋轉的角度,然後再放大;但它不喜歡它,但初始參數和初始回調是相同的;我敢肯定有一個更好的方式來調用遞歸,但希望這可以給你的,你怎麼能在功能上動畫的想法:

//initial zoom 
static final int initZoom = 8; 
//steps the zoom 
int stepZoom = 0; 
// number of steps in zoom, be careful with this number! 
int stepZoomMax = 5; 
//number of .zoom steps in a step 
int stepZoomDetent = (18 - initZoom)/stepZoomMax; 
//when topause zoom for spin 
int stepToSpin = 4; 
//steps the spin 
int stepSpin = 0; 
//number of steps in spin (factor of 360) 
int stepSpinMax = 4; 
//number of degrees in stepSpin 
int stepSpinDetent = 360/stepSpinMax; 

Intent detailIntent; 
Intent intent; 
Marker marker; 
final int mapHopDelay = 2000; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.map_affirm); 
    try 
    {MapsInitializer.initialize(this);} 
    catch (GooglePlayServicesNotAvailableException impossible) 
    { /* Impossible */ Log.e(TAG, "the impossible occurred");} 
    intent = this.getIntent(); 
    latLng = new LatLng(intent.getDoubleExtra("Latitude", 0.0), intent.getDoubleExtra("Longitude", 0.0)); 
    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 
    map.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder() 
                  .target(latLng) 
                  .zoom(initZoom-1) 
                  .build()) 
         , mapHopDelay 
         , cameraAnimation 
        ); 
    marker = map.addMarker(new MarkerOptions() 
          .draggable(true) 
          .position(latLng) 
          .title("Location of Photographer")); 

} 

public CancelableCallback cameraAnimation = new CancelableCallback(){ 

    @Override 
    public void onFinish() 
    { 
     if (stepZoom < stepZoomMax && stepZoom != stepToSpin) 
     { 
      stepZoom++; 
      map.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder() 
                    .target(latLng) 
                    .zoom(initZoom + (stepZoomDetent * (stepZoom - 1))) 
                    // .bearing(40*aniStep) 
                    // .tilt(60) 
                    .build()), mapHopDelay, cameraAnimation); 

     } 
     else if (stepZoom >= stepZoomMax)// ending position hard coded for this application 
     {map.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder() 
                   .target(latLng) 
                   .zoom(18) 
                   // .bearing(0) 
                   .tilt(0) 
                   .build())); 
     } 
     else 
     { 
      if (stepSpin <= stepSpinMax) 
      { 
       stepSpin++; 
       map.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder() 
                     .target(latLng) 
                     .zoom(initZoom + stepZoomDetent * stepZoom) 
                     .bearing(stepSpinDetent * (stepSpin - 1)) 
                     .tilt(60) 
                     .build()), mapHopDelay, cameraAnimation); 
      } 
      else 
      { 
       stepZoom++; 
       map.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder() 
                     .target(latLng) 
                     .zoom(initZoom + stepZoomDetent * stepZoom) 
                     .bearing(0) 
                     .tilt(0) 
                     .build()), mapHopDelay, cameraAnimation); 
      } 
     } 
    } 

    @Override 
    public void onCancel() 
    {} 

}; 
+1

嗨!聽起來很有趣,我沒有使用回調,會試試看。感謝您發佈代碼! – rupps