1

如何为地图上的第二点使用不同的图像

package com.Android.WiC_MobileApp;


import java.util.ArrayList;
import java.util.List;

import com.Android.WiC_MobileApp.MapMarkerActivity;
import com.Android.WiC_MobileApp.R;
import com.Android.WiC_MobileApp.MapMarkerActivity.SitesOverlay;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MapMarkerActivity extends MapActivity {

     private MapView map=null;
      private MyLocationOverlay me=null;


      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.particular_entry);


        map=(MapView)findViewById(R.id.map);

        map.getController().setCenter(getPoint(FeedListViewActivity.lat,
                FeedListViewActivity.lng));
        map.getController().setZoom(13);
        map.setBuiltInZoomControls(true);

        Drawable marker1=getResources().getDrawable(R.drawable.marker);

        Drawable marker2=getResources().getDrawable(R.drawable.ic_launcher);

        marker1.setBounds(0, 0, marker1.getIntrinsicWidth(),
                                marker1.getIntrinsicHeight());

        map.getOverlays().add(new SitesOverlay(marker1));

        me=new MyLocationOverlay(this, map);
        map.getOverlays().add(me);
      }

      @Override
      public void onResume() {
        super.onResume();

        me.enableCompass();
      }   

      @Override
      public void onPause() {
        super.onPause();

        me.disableCompass();
      }   

      @Override
      protected boolean isRouteDisplayed() {
        return(false);
      }

      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_S) {
          map.setSatellite(!map.isSatellite());
          return(true);
        }
        else if (keyCode == KeyEvent.KEYCODE_Z) {
          map.displayZoomControls(true);
          return(true);
        }

        return(super.onKeyDown(keyCode, event));
      }

      private GeoPoint getPoint(double lat, double lon) {
        return(new GeoPoint((int)(lat*1000000.0),
                              (int)(lon*1000000.0)));
      }

      public class SitesOverlay extends ItemizedOverlay<OverlayItem> {
        private List<OverlayItem> items=new ArrayList<OverlayItem>();

        public SitesOverlay(Drawable marker) {
          super(marker);

          boundCenterBottom(marker);

          items.add(new OverlayItem(getPoint(MyLocationActivity.myLocationLatitude,
                                              MyLocationActivity.myLocationLongitude),
                                    "YL", "Your Location"));

          items.add(new OverlayItem(getPoint(FeedListViewActivity.lat,
                                              FeedListViewActivity.lng),
                                    "SL",
                                    "Store Location"));

          populate();
        }

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

        @Override
        protected boolean onTap(int i) {
          Toast.makeText(MapMarkerActivity.this,
                          items.get(i).getSnippet(),
                          Toast.LENGTH_SHORT).show();

          return(true);
        }

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

}

在 SitesOverlay(Drawable marker) 方法中,我添加了 2 个覆盖项,我两者都有所不同....我找到了一些其他类型的代码来实现这个....使用 draw 方法....但是如何在这个中实现案例....请帮助...谢谢

4

1 回答 1

0

要简单地回答您的问题,您所要做的就是将此行添加到您的 onCreate 方法中:

map.getOverlays().add(new SitesOverlay(marker2));

我认为我不太了解您所面临的问题,因为我无法理解您对问题的描述。我要提到的是,您应该使用要使用的标记构造一个 SitesOverlay,然后构造一个 OverlayItem,然后将该 OverlayItem 添加到 SitesOverlay,然后将 SitesOverlay 添加到 map.getOverlays.add(...); 我已经修改了你的大部分代码以澄清我上面的意思。希望这可以帮助!不要犹豫,问我任何进一步的问题。

package com.Android.WiC_MobileApp;


import java.util.ArrayList;
import java.util.List;

import com.Android.WiC_MobileApp.MapMarkerActivity;
import com.Android.WiC_MobileApp.R;
import com.Android.WiC_MobileApp.MapMarkerActivity.SitesOverlay;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MapMarkerActivity extends MapActivity {

 private MapView map=null;
  private MyLocationOverlay me=null;


  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.particular_entry);


    map=(MapView)findViewById(R.id.map);

    map.getController().setCenter(getPoint(FeedListViewActivity.lat,
            FeedListViewActivity.lng));
    map.getController().setZoom(13);
    map.setBuiltInZoomControls(true);

    Drawable marker1=getResources().getDrawable(R.drawable.marker);

    Drawable marker2=getResources().getDrawable(R.drawable.ic_launcher);

    SitesOverlay sitesOverlay1 = new SitesOverlay(marker1);
    OverlayItem item1 = new OverlayItem(getPoint(MyLocationActivity.myLocationLatitude,
                                          MyLocationActivity.myLocationLongitude),
                                "YL", "Your Location");
    sitesOverlay1.addOverlay(item1);
    map.getOverlays().add(sitesOverlay1);

    SitesOverlay sitesOverlay2 = new SitesOverlay(marker2);
    OverlayItem item2 = new OverlayItem(getPoint(FeedListViewActivity.lat,
                                          FeedListViewActivity.lng),
                                "SL",
                                "Store Location"));
    sitesOverlay2.addOverlay(item2);
    map.getOverlays.add(sitesOverlay2)

    me=new MyLocationOverlay(this, map);
    map.getOverlays().add(me);
  }

  @Override
  public void onResume() {
    super.onResume();

    me.enableCompass();
  }   

  @Override
  public void onPause() {
    super.onPause();

    me.disableCompass();
  }   

  @Override
  protected boolean isRouteDisplayed() {
    return(false);
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_S) {
      map.setSatellite(!map.isSatellite());
      return(true);
    }
    else if (keyCode == KeyEvent.KEYCODE_Z) {
      map.displayZoomControls(true);
      return(true);
    }

    return(super.onKeyDown(keyCode, event));
  }

  private GeoPoint getPoint(double lat, double lon) {
    return(new GeoPoint((int)(lat*1000000.0),
                          (int)(lon*1000000.0)));
  }

  public class SitesOverlay extends ItemizedOverlay<OverlayItem> {
    private List<OverlayItem> items=new ArrayList<OverlayItem>();

    public SitesOverlay(Drawable marker) {
      super(boundCenterBottom(marker));
      populate();
    }

    private void addOverlay(OverlayItem overlayItem)
    {
     items.add(overlayItem);
    }

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

    @Override
    protected boolean onTap(int i) {
      Toast.makeText(MapMarkerActivity.this,
                      items.get(i).getSnippet(),
                      Toast.LENGTH_SHORT).show();

      return(true);
    }

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

}

于 2012-07-09T19:20:16.093 回答