问问题
324 次
1 回答
2
AddItemized Overlay class:
public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
public AddItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public AddItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
Log.e("Tap", "Tap Performed");
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
}
Use this code in your Activity
List<Overlay> mapOverlays = mv.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.drawable);
AddItemizedOverlay itemizedOverlay =
new AddItemizedOverlay(drawable, this);
OverlayItem overlayitem = new OverlayItem(gp, "Hello", "I am here");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
public void createMapViewForHaritaFragment(IlanList list)
{
IlanList gelenListe;
gelenListe=list;
if(gelenListe!=null)
{
MainActivity parent = getParentActivity();
mMapViewContainer = parent.getmMapViewContainer();
mMapView = parent.getmMapView();
/**/
mc = mMapView.getController();
LocationManager lm = (LocationManager) parent.getSystemService(parent.getApplicationContext().LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
String longitude = String.valueOf(location.getLongitude()).substring(0, 9);
String latitude = String.valueOf(location.getLatitude()).substring(0, 9);
String coordinates[] = {latitude,longitude};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc = mMapView.getController();
mc.setCenter(p);
mc.setZoom(16);
List<Overlay> mapOverlays = mv.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.pin);
AddItemizedOverlay itemizedOverlay = new AddItemizedOverlay(drawable,
this);
OverlayItem overlayitem = new OverlayItem(p, "Hello", "I AM HERE");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
/* mc.animateTo(p);
mMapView.setBuiltInZoomControls(true);
mMapView.setSatellite(false);
mc.setZoom(16); */
/*Harita
public View mMapViewContainer;
public MapView mMapView;
public MapController mc;
public GeoPoint p;
public List<Overlay> mapOverlays;
public Drawable drawable;
public MapItemizedOverlay itemizedOverlay;
Harita*/
/* drawable = this.getResources().getDrawable(R.drawable.map_kirmizi_png);
itemizedOverlay = new MapItemizedOverlay(drawable, parent.getApplicationContext(), 30);//text size: 30
GeoPoint gPointMe = new GeoPoint(41099932,29002657);
OverlayItem overlayItem = new OverlayItem(gPointMe, "Me", "This is my location");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
mMapView.setBuiltInZoomControls(true);
//move map over to my position
mc.animateTo(gPointMe);
mMapView.invalidate(); */
}
}
于 2012-12-21T11:16:50.797 回答