1

我需要一些方法来移动地图视图中道路上的公共汽车图标。我有地理点数组,其中包含公共汽车需要通过的所有坐标经度和纬度点,我还需要沿路线创建一些“位移动画”

我使用 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;
    }

}

在我的活动类中,我使用了 Runable 方法

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

但是效果不好。。

请帮我。

4

0 回答 0