Google MapView 上的动画标记

发布于 2024-12-16 10:46:28 字数 990 浏览 0 评论 0原文

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

以下是 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

谢谢您的

宝贵时间,

汤姆。

I am working on an Android app that displays multiple markers on a Google MapView. Everything works perfectly but I would like the markers to have an animation when they appear on the map.

Here's an example of something similar on iPhone. See 1'20".

Here is how I add them to my 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

It is so pretty on iPhone, and someone must have already done something similar on Android but I can't seem to find any useful info.

EDIT: Okay so I recon I either have to override the draw method which will be long and not that pretty, or just give up with OverlayItems.

Thank you for your time.

Best regards,

Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半步萧音过轻尘 2024-12-23 10:46:28

您可以使用本教程< /a> 作为参考,它使用动画,所以我认为这适合您的解决方案。

教程中的代码:

//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);
 }

You can use this tutorial for a reference, it uses animations, so I think that suits your solution.

Code from the 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);
 }
甜扑 2024-12-23 10:46:28

我看到了你的示例应用程序。由此看来,我认为你只需要在你的标记中发光,对吗?如果是,那么可以通过样式并且它也具有发光属性。

I seen your example app. From that i think you need only Glow in your markers, right? If yes then its possible through the styles and its having glow property also.

浅黛梨妆こ 2024-12-23 10:46:28

所以我使用简单的 ImageViews ArrayList 和动画来让它工作,没有 MapOverlay。

So I got it to work using a simple ArrayList of ImageViews and animation on them, no MapOverlay.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文