2011-11-18 75 views
2

我正在研究在Google MapView上顯示多個標記的Android應用程序。一切都很完美,但我希望標記在地圖上出現時具有動畫。在Google MapView上動畫標記

Here's an example在iPhone上類似的東西。見1'20" 。

這是我如何將它們添加到我的MapView。

for(int i=0; i<myMarkerList.length(); i++){ 
GeoPoint x = new GeoPoint(
       (int)(lat*1E6), 
        (int)(lng*1E6)); 

     oItem = new OverlayItem(x, title, String.valueOf(nb_marker)); 
     pin.setAlpha(255); 
     oItem.setMarker(pin);   

     if (oItem != null)    
      mapOverlay.addOverlay(oItem); // add the overlay item to the overlay    
     }    
     mapOverlays.add(mapOverlay); // add the overlay to the list of overlays 
     mapView.invalidate(); // update the map shown 

這是在iPhone上這麼漂亮,而且必須有人已經做了類似的事情在Android上,但我似乎無法找到任何有用的信息

編輯:好了,所以我偵察我要麼必須重寫,這將是長期的抽籤方法並不算漂亮,或者乾脆放棄使用OverlayItems

謝謝您的時間。

最好的問候,

湯姆

回答

0

所以我得到它使用一個簡單的ArrayList的ImageViews和動畫對他們,沒有MapOverlay。

+0

嗨湯姆,你能告訴我一個例子,你如何實現你的問題,因爲我也在尋找解決方案。如果你能向我展示一個例子,這將非常有幫助。 – ferhan

+0

@TechGeeky hi隊友我堅持這從最近幾天,但無法找到方式...我有一個同樣的問題,我希望你可以在這個問題上取得成功。在這裏註釋,希望你可以理解我的感受,如果這解決了我..plzz幫助提前感謝了很多 –

0

可以使用this tutorial一個參考,它使用了動畫,所以我覺得適合你的解決方案。從教程

代碼:

//Reference to our MapView 
MapView mapView = (MapView) activity.findViewById(R.id.mapview); 

//Get a LayoutInflater and load up the view we want to display. 
//The false in inflater.inflate prevents the bubble View being added to the MapView straight away 
LayoutInflater inflater = activity.getLayoutInflater(); 
LinearLayout bubble = (LinearLayout) inflater.inflate(R.layout.bubble, mapView, false); 

//Set up the bubble's close button 
ImageButton bubbleClose = (ImageButton) bubble.findViewById(R.id.bubbleclose); 
bubbleClose.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 
     Animation fadeOut = AnimationUtils.loadAnimation(ResultsMapResultsDisplayer.this.activity, R.anim.fadeout); 
     bubble.startAnimation(fadeOut); 
     bubble.setVisibility(View.GONE); 
    } 
}); 

private void displaySearchResultBubble(final SearchResult result) { 
    //Hide the bubble if it's already showing for another result 
    map.removeView(bubble); 
    bubble.setVisibility(View.GONE); 

    //Set some view content 
    TextView venueName = (TextView) bubble.findViewById(R.id.venuename); 
    venueName.setText(result.getName()); 

    //This is the important bit - set up a LayoutParams object for positioning of the bubble. 
    //This will keep the bubble floating over the GeoPoint result.getPoint() as you move the MapView around, 
    //but you can also keep the view in the same place on the map using a different LayoutParams constructor 
    MapView.LayoutParams params = new MapView.LayoutParams(
     LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 
     result.getPoint(), MapView.LayoutParams.BOTTOM_CENTER); 

    bubble.setLayoutParams(params); 

    map.addView(bubble); 
    //Measure the bubble so it can be placed on the map 
    map.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 

    //Runnable to fade the bubble in when we've finished animatingTo our OverlayItem (below) 
    Runnable r = new Runnable() { 
     public void run() { 
      Animation fadeIn = AnimationUtils.loadAnimation(activity, R.anim.fadein); 
      bubble.setVisibility(View.VISIBLE); 
      bubble.startAnimation(fadeIn); 
     } 
    }; 

    //This projection and offset finds us a new GeoPoint slightly below the actual OverlayItem, 
    //which means the bubble will end up being centered nicely when we tap on an Item. 
    Projection projection = map.getProjection(); 
    Point p = new Point(); 

    projection.toPixels(result.getPoint(), p); 
    p.offset(0, -(bubble.getMeasuredHeight()/2)); 
    GeoPoint target = projection.fromPixels(p.x, p.y); 

    //Move the MapView to our point, and then call the Runnable that fades in the bubble. 
    mapController.animateTo(target, r); 
} 
+0

嘿裏諾,我在Google上搜索信息時遇到了本教程,但我相信這不會做我想找的。動畫中有一個淡入淡出的效果,但它在一個佈局上播放,而不是像我這樣的OverlayItem。無論如何,我會嘗試一下。乾杯 – Tom

0

我看過你的示例應用程序。從這我認爲你只需要在你的標記發光,對吧?如果是,那麼它可能通過風格和它的輝光屬性也。

+0

嗨蠍子,其實發光的風格是可選的,最重要的是它們出現的方式,它們具有某種彈跳效果的比例。 – Tom