3

In my application I have a map-activity which uses OSMDroid. I've managed to manually add markers with Overlay to display different locations but I want to implement a function where a marker will be created when you either double-tap or longpress. I've scavenged the web for some kind of good explanation since I've troubles understanding the documentation of OSMDroid and their bonuspack.

Here is my relevant code:

public class Map extends Activity{

MapView mapView;
MapController mapController;
ArrayList<OverlayItem> overlayItemArray;

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

    mapView = (MapView) this.findViewById(R.id.mapView);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapController = (MapController) mapView.getController();
    mapController.setZoom(14);

    GeoPoint startPoint = new GeoPoint(58.4109, 15.6216);
    mapController.setCenter(startPoint);

    // Create an ArrayList with overlays to display objects on map
    overlayItemArray = new ArrayList<OverlayItem>();

    // Create som init objects
    OverlayItem linkopingItem = new OverlayItem("Linkoping", "Sweden",
            new GeoPoint(58.4109, 15.6216));
    OverlayItem stockholmItem = new OverlayItem("Stockholm", "Sweden",
            new GeoPoint(59.3073348, 18.0747967));

    // Add the init objects to the ArrayList overlayItemArray
    overlayItemArray.add(linkopingItem);
    overlayItemArray.add(stockholmItem);

    // Add the Array to the IconOverlay
    ItemizedIconOverlay<OverlayItem> itemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(this, overlayItemArray, null);

    // Add the overlay to the MapView
    mapView.getOverlays().add(itemizedIconOverlay);

}
Wouter J
  • 41,455
  • 15
  • 107
  • 112
willedanielsson
  • 1,333
  • 3
  • 11
  • 14
  • 2
    Duplicate with: http://stackoverflow.com/questions/20946715/osmdroid-adding-a-marker-when-user-taps-on-map http://stackoverflow.com/questions/22804650/how-to-handle-long-press-on-a-map-using-osmdroid-osmbonuspack-in-android (Use longPressHelper) – MKer Apr 10 '14 at 16:39
  • Use the OSMbonuspack for mapeventsoverlay. https://code.google.com/p/osmbonuspack/source/browse/trunk/OSMBonusPack/src/org/osmdroid/bonuspack/overlays/MapEventsOverlay.java – Henning Hall Apr 11 '14 at 08:00

0 Answers0