Android,如何在地图上制作动画叠加层?

时间:2012-06-01 10:47:39

标签: android android-mapview android-maps

请指导我如何在地图上制作动画标记/图钉/叠加图标。 我从最近2天开始尝试了很多,但我没有成功。

提前致谢..

无效

RES /抽拉/ map_marker.xml

 <?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
 android:oneshot="false">
<item android:drawable="@drawable/ecall_lowon" android:duration="200" />
<item android:drawable="@drawable/ecall_mediumoff" android:duration="200" />

Java代码

    Drawable drawable = this.getResources().getDrawable(R.drawable.map_marker);
    MapItemizedOverlay mapItemizedOverlay = new MapItemizedOverlay(drawable, this);

    GeoPoint geoPoint1 = new GeoPoint((int)(9.982878 * 1E6), (int)(76.285774 * 1E6));
    GeoPoint geoPoint2 = new GeoPoint((int)(9.973928 * 1E6), (int)(76.276824 * 1E6));

    OverlayItem overlayItem1 = new OverlayItem(geoPoint1, "Title1", "");
    OverlayItem overlayItem2 = new OverlayItem(geoPoint2, "Title2", "");

    mapItemizedOverlay.addOverlayItems(overlayItem1);
    mapItemizedOverlay.addOverlayItems(overlayItem2);

    mapView.getOverlays().add(mapItemizedOverlay);

但没有成功......

1 个答案:

答案 0 :(得分:5)

以XML格式定义的动画按顺序显示一系列图像(<animation-list /&gt;)可能无法在地图上显示闪烁图钉

我已经解决了这个问题并找到了解决方案之一

想法:两个drawables ..,Runnablehandler SetPin_On() SetPin_Off() ,在SetPin_On方法中使用一个图像并在SetPin_Off方法中使用另一个图像,在每个函数上调用clear overlay并再次添加

资源:取两张图片说pin_on,pin_off

编码:需要使用处理程序运行,以便按间隔设置引脚

示例:

Handler handler=new Handler();
      int check=0;

          Runnable r=new Runnable()
          {

        @Override
        public void run() 
        {
             if(check==0)
             {
               SetPin_On();
               check=1;

             }
             else if(check==1)
             {
               SetPin_Off();
               check=0;
             }
            handler.postDelayed(this, 500);
        }

    };

SetPin_On 方法中,在叠加上设置pin_on图像,并在 SetPin_Off 方法中再次通过清除上一个叠加设置pin_off图像

<强> SetPin_On:

void SetPin_On()
    {
         mapOverlays = mapView.getOverlays();
         mapOverlays.clear(); 

         res =getResources(); 
         drawable = res.getDrawable(R.drawable.pin_on);
         itemizedOverlay = new CustomItemizedOverlay(drawable,this, mapView);


         point = new GeoPoint((int)(Double.parseDouble(lati)*1E6),(int)(Double.parseDouble(longi)*1E6));
         overlayitem = new OverlayItem(point, "Hello", "I'm in Athens, Greece!");

         itemizedOverlay.addOverlay(overlayitem);
         mapOverlays.add(itemizedOverlay);

         mapController = mapView.getController();

         mapController.animateTo(point);
         mapController.setZoom(6);
    }

<强> SetPin_Off:

void SetPin_Off()
    {

        mapOverlays = mapView.getOverlays();
         mapOverlays.clear(); 

         res =getResources(); 
         drawable = res.getDrawable(R.drawable.pin_off);
         itemizedOverlay = new CustomItemizedOverlay(drawable,this, mapView);


         point = new GeoPoint((int)(Double.parseDouble(lati)*1E6),(int)(Double.parseDouble(longi)*1E6));
         overlayitem = new OverlayItem(point, "Hello", "I'm in Athens, Greece!");

         itemizedOverlay.addOverlay(overlayitem);
         mapOverlays.add(itemizedOverlay);

         mapController = mapView.getController();

         mapController.animateTo(point);
         mapController.setZoom(6);

    }

这是获得闪烁pin的一种解决方案。虽然效率不高但结果非常准确

See here寻求其他解决方案