Mapview移动汽车图标

时间:2012-11-01 08:04:46

标签: android android-layout android-intent android-mapview

我需要一些方法在mapview中的道路上移动公交车图标。 我有GeoPoint数组,其中包含需要通过的所有坐标长度和纬度点,我还需要在路线上创建一些“置换动画”

我使用Overlay类每1秒设置一个总线图标

class BusOverlay extends ItemizedOverlay<OverlayItem> {

    private Context context = null;
    private List<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private MediaPlayer mediaPop;

    public BusOverlay(Drawable defaultMarker, Context context) {
        super(boundCenterBottom(defaultMarker));
        this.context = context;
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        return mOverlays.size();
    }

    public void addOverlayItem(OverlayItem overlayItem) {
        mOverlays.add(overlayItem);
        populate();
    }

    public void addOverlayItem(int lat, int lon, String title) {
        GeoPoint point = new GeoPoint(lat, lon);
        OverlayItem overlayItem = new OverlayItem(point, title, title);

        addOverlayItem(overlayItem);
    }

    public void removeOverlay(OverlayItem overlay) {
        mOverlays.remove(overlay);
        populate();
    }

    public void removeOverlayItem(int lat, int lon, String title) {
        GeoPoint point = new GeoPoint(lat, lon);
        OverlayItem overlayItem = new OverlayItem(point, title, title);

        removeOverlay(overlayItem);
    }

    protected boolean onTap(int index) {

        super.onTap(index);


        return true;
    }

}

在My Activity类中,我使用Runable methode

Drawable busLocationIcon = this.getResources().getDrawable(
                R.drawable.bus_location);
        final BusOverlay itemizedBusLocartionOverlay = new BusOverlay(
                busLocationIcon, this);

        int countBus = 0;
        myRunnable = new Runnable() {
            public void run() {

                try {



                    itemizedBusLocartionOverlay.addOverlayItem((int) (Double
                            .parseDouble(Main.jsonArrayBus.getJSONObject(
                                    countBus).getString("StopLat")) * 1000000),
                            (int) (Double.parseDouble(Main.jsonArrayBus
                                    .getJSONObject(countBus).getString(
                                            "StopLon")) * 1000000), "The Bus");

                    countBus++;

                    mapView.getOverlays().add(itemizedBusLocartionOverlay);
                } catch (NumberFormatException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                //Hendler
                h.postDelayed(myRunnable, 1000);
            }
        };
        h.postDelayed(myRunnable, 1000);

但是效果不好......

请帮帮我。

0 个答案:

没有答案
相关问题