【发布时间】:2016-09-25 17:20:16
【问题描述】:
我的应用正在使用本地服务,该服务提供不断变化的位置。 这些位置已添加到我的 ArrayList:
static List<Location> weg = new ArrayList<Location>();
WegAnsehenActivity 现在显示连接点的路径。
我的目标:我想将路径上的图标更改为最后一个当前点
完成:我想改变最后一个位置的绿色箭头
我的问题:我怎样才能做到这一点?
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.PathOverlay;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
.
.
.
public class WegAnsehenActivity extends Activity {
MapView mapView;
IMapController mapController;
MyLocationNewOverlay o;
Paint paint;
PathOverlay overlay;
//filled by the local service, method onLocationChanged
static List<Location> weg = new ArrayList<Location>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
mapController = mapView.getController();
//false keeps the mapView from loading online tiles using network connection!!!
mapView.setUseDataConnection(false);//true);
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(7);
paint.setColor(Color.BLUE);
overlay = new PathOverlay(Color.BLUE, this);
overlay.setPaint(paint);
o = new MyLocationNewOverlay(getApplicationContext(), mapView);
}
@Override
protected void onResume() {
super.onResume();
mapController.setZoom(16);
if (weg.size() >= 1) {
for (int i = 0; i < weg.size(); i++) {
if (i==weg.size()-1) {
mapController.setCenter(new GeoPoint(weg.get(i).getLatitude(), weg.get(i).getLongitude()));
}
GeoPoint point = new GeoPoint(weg.get(i));
overlay.addPoint(point);
}
mapView.getOverlayManager().add(overlay);
o.enableMyLocation(); //shows a green arrow I want to replace
mapView.getOverlays().add(o);
mapView.postInvalidate();
}
}
}
请帮忙!
问候维姬
【问题讨论】:
-
根据我的经验,osmdroid 不允许您更改现有点的图标。唯一的解决办法就是删除再删除再添加