0

我需要在地图上显示自定义信息作为 Pin 上的用户磁带。我正在起诉 Balloon 地图叠加,我需要显示的信息来自 Web 服务,例如虚拟信息如下 - 时间 - 名称 - 电池状态 - 以及其他一些信息 在此先感谢

4

1 回答 1

0

这对我有用,请记住更改包名称,如果您有任何错误,请询问

 package com.utility;

    import java.util.ArrayList;

    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.drawable.Drawable;

    import com.google.android.maps.MapView;
    import com.google.android.maps.OverlayItem;

    public class MyItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {

        private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
        private Context c;
        private Drawable marker;
        private String mFlag;

        public MyItemizedOverlay(Drawable marker, MapView mapView, String mFlag) {
            super(boundCenter(marker), mapView);
            this.marker = marker;
            c = mapView.getContext();
            this.mFlag = mFlag;
        }

        public void addOverlay(OverlayItem overlay) {
            m_overlays.add(overlay);
            populate();
        }

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

        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
            super.draw(canvas, mapView, shadow);

            boundCenterBottom(marker);
        }

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

        public void clear() {
            m_overlays.clear();
            populate();
        }

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

        @Override
        protected boolean onBalloonTap(int i) {

            return true;
        }

    }


MyItemizedOverlay mItemizedOverlay = new MyItemizedOverlay(marker1, mMapView, "AnyName"); //here marker1 is your pin in drawable like - getResources().getDrawable(R.drawable.pin_red);

//here mMapView is your mapview object that you have defined in your xml

List<Overlay> mapOverlays = mMapView.getOverlays();

//now when you get response from server put this code

GeoPoint newPoint = new GeoPoint(
                                (int) (Double.parseDouble(mLat) * 1E6),
                                (int) (Double.parseDouble(mLong) * 1E6));
                        Geocoder geoCoder = new Geocoder(getBaseContext(),
                                Locale.getDefault());
                        String _destinationAdd = ConvertPointToLocation(newPoint);

                        if (!mUserInfo.mLat.equals("null")
                                || mUserInfo.mLat != null
                                && !mUserInfo.mLong.equals("null")
                                || mUserInfo.mLong != null) {

                            OverlayItem overlayItem = new OverlayItem(
                                    newPoint,

                                            "Location : " + _destinationAdd,
                                    null);
                            itemizedOverlay.clear();

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

                            mMapView.getController()
                                    .animateTo(
                                            getPoint(
                                                    Double.parseDouble(mUserInfo.mLat),
                                                    Double.parseDouble(mUserInfo.mLong)));
                            mMapView.getController()
                                    .setCenter(
                                            getPoint(
                                                    Double.parseDouble(mUserInfo.mLat),
                                                    Double.parseDouble(mUserInfo.mLong)));
                            mMapView.getController().setZoom(15);
                        }
                        mMapView.invalidate();
于 2013-02-14T07:50:56.380 回答