Это должно работать ОК
.
public class SampleWithMinimapItemizedoverlay extends Activity implements
LocationListener, MapViewConstants {
private MapView mMapView;
private MapController mapController;
private LocationManager mLocMgr;
private ItemizedOverlay<OverlayItem> mMyLocationOverlay;
private ResourceProxy mResourceProxy;
int mLongtitude = 31987968;
int mLatitude = 34783155;
ArrayList<OverlayItem> mItems;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
setContentView(R.layout.main);
mMapView = (MapView) this.findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mapController = this.mMapView.getController();
mapController.setZoom(15);
GeoPoint point2 = new GeoPoint(mLongtitude, mLatitude); // centre map here
GeoPoint point3 = new GeoPoint(mLongtitude + 2000, mLatitude + 2000); // icon
// goes
// 31.987968,34.783155
mapController.setCenter(point2);
mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100,
this);
mItems = new ArrayList<OverlayItem>();
// Put overlay icon a little way from map centre
mItems.add(new OverlayItem("Here", "SampleDescription", point3));
/* OnTapListener for the Markers, shows a simple Toast. */
// REFER TO THE GESTURE LISTEMER BY NAME NOW
this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems,
new Glistener() , mResourceProxy);
this.mMapView.getOverlays().add(this.mMyLocationOverlay);
mMapView.invalidate();
}
//We can't use an anonymous class anymore if we want to change the position
// of the overlays/icons when location changed, give it a name
class Glistener implements OnItemGestureListener<OverlayItem> {
@Override
public boolean onItemLongPress(int index, OverlayItem item) {
Toast.makeText(SampleWithMinimapItemizedoverlay.this, "Item " + item.mTitle,
Toast.LENGTH_LONG).show();
return false;
}
@Override
public boolean onItemSingleTapUp(int index, OverlayItem item) {
Toast.makeText(SampleWithMinimapItemizedoverlay.this, "Item " + item.mTitle,
Toast.LENGTH_LONG).show();
return true; // We 'handled' this event.
}
}
// -------//here I tried to do the change !!!!!!!!!---------------
// -- The map location being updated but not the overlayItem.
public void onLocationChanged(Location location) {
mLatitude = (int) (location.getLatitude() * 1E6);
mLongtitude = (int) (location.getLongitude() * 1E6);
Toast.makeText(SampleWithMinimapItemizedoverlay.this,
"Location changed. Lat:" + mLatitude + " long:" + mLongtitude,
Toast.LENGTH_LONG).show();
GeoPoint gpt = new GeoPoint(mLatitude, mLongtitude);
mapController.setCenter(gpt);
mItems.clear(); // COMMENT OUT THIS LINE IF YOU WANT A NEW ICON FOR EACH CHANGE OF POSITION
mItems.add(new OverlayItem("New", "SampleDescription", gpt));
// Change the overlay
this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems,
new Glistener() , mResourceProxy);
this.mMapView.getOverlays().clear();
this.mMapView.getOverlays().add(this.mMyLocationOverlay);
mMapView.invalidate();
}
@Override
public void onProviderDisabled(String arg0) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
Просто прокомментируйте / раскомментируйте mItems.clear ();линия в зависимости от того, хотите ли вы новый маркер каждый раз, когда вы меняете положение.(Значок отображается в той позиции, в которую вы переместились)