【问题标题】:Animate markers on Google MapViewGoogle MapView 上的动画标记
【发布时间】:2011-11-18 09:33:42
【问题描述】:

我正在开发一个在 Google MapView 上显示多个标记的 Android 应用程序。一切正常,但我希望标记出现在地图上时有动画。

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 上做过类似的事情,但我似乎找不到任何有用的信息。

编辑:好的,所以我认为我要么必须重写会很长且不那么漂亮的 draw 方法,要么就放弃 OverlayItems。

感谢您的宝贵时间。

最好的问候,

汤姆

【问题讨论】:

    标签: android google-maps animation android-mapview marker


    【解决方案1】:

    您可以使用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);
     }
    

    【讨论】:

    • 嘿 Reno,我在 Google 上搜索信息时遇到了这个教程,但我相信这并不能满足我的要求。动画有淡入淡出,但它是在 Layout 上投射的,而不是像我这样的 OverlayItem。无论如何,我会尝试一下。干杯
    【解决方案2】:

    我看到了您的示例应用程序。从那我认为你只需要在你的标记中发光,对吧?如果是,那么它可能通过样式和具有发光属性。

    【讨论】:

    • 嗨 Scorpion,实际上发光样式是可选的,最重要的是它们的显示方式,它们具有某种弹跳效果。
    【解决方案3】:

    所以我使用了一个简单的 ImageView ArrayList 和动画,没有 MapOverlay。

    【讨论】:

    • 嗨,汤姆,你能告诉我一个例子,你是如何解决你的问题的,因为我也在寻找解决方案。如果你能给我举个例子,那会很有帮助。
    • @TechGeeky 嗨,伙计,我从最近几天就被这个问题困住了,但找不到方法……我有同样的问题,我希望你能在这个问题上取得成功……在这里发表评论,希望如果这为我解决了,你可能会理解我的感受..plzz 帮助提前非常感谢
    猜你喜欢
    • 2018-04-23
    • 2013-01-29
    • 1970-01-01
    • 2018-02-03
    • 2013-01-27
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多