2
我是新開的街道地圖地圖。我想把標記放在我點擊的地圖上。我也想刪除以前的標記。請幫幫我。提前致謝。這是我的代碼。我在這個問題請求中從2天掙扎。在openstreetmap上單擊繪製標記android
Overlay touchOverlay = new Overlay(this) {
ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = null;
@Override
protected void draw(Canvas arg0, MapView arg1, boolean arg2) {
}
@Override
public boolean onSingleTapConfirmed(final MotionEvent e,
final MapView mapView) {
Projection proj = mapView.getProjection();
GeoPoint loc = (GeoPoint) proj.fromPixels((int) e.getX(),
(int) e.getY());
String longitude = Double
.toString(((double) loc.getLongitudeE6())/1000000);
String latitude = Double
.toString(((double) loc.getLatitudeE6())/1000000);
Toast toast = Toast.makeText(getApplicationContext(), "Longitude:"
+ longitude + " Latitude: " + latitude, Toast.LENGTH_SHORT);
toast.show();
ArrayList<OverlayItem> overlayArray = new ArrayList<OverlayItem>();
OverlayItem mapItem = new OverlayItem("", "", new GeoPoint(
(((double) loc.getLatitudeE6())/1000000),
(((double) loc.getLongitudeE6())/1000000)));
mapItem.setMarker(marker);
overlayArray.add(mapItem);
if (anotherItemizedIconOverlay == null) {
anotherItemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(
getApplicationContext(), overlayArray, null);
mapView.getOverlays().add(anotherItemizedIconOverlay);
mapView.invalidate();
} else {
mapView.getOverlays().remove(anotherItemizedIconOverlay);
mapView.invalidate();
anotherItemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(
getApplicationContext(), overlayArray, null);
mapView.getOverlays().add(anotherItemizedIconOverlay);
}
return true;
}
};
的可能重複[位置變化,並把標記上單擊OpenStreetMap的(http://stackoverflow.com/questions/19403420/location-change-and-put-marker-on-click-in-openstreetmap ) – scai
它也是我的代碼。它不工作 –