Skip to content Skip to sidebar Skip to footer

How To Add A Marker When I Touch The Map In Android ?

I have a map activity which displays the map, I want to add a marker when I touch on the screen .. This is my Activity ... package com.adhamenaya.android; import java.util.List;

Solution 1:

Hello, MapView! tutorial covers showing markers on MapView. In the tutorial markers are added as soon as the activity starts, but you can also add markers at later time, for example, when user touches screen. If you try this approach, you'll likely want to override onTap in your subclass of ItemizedOverlay.

Update:

If you follow the tutorial, you'll have your own subclass of ItemizedOverlay. onTap is one of its methods. Now that I look at the documentation, unfortunately onTap(GeoPoint p, MapView mapView) is not public or protected so you cannot override it.

What you can do, is have another overlay, solely for detecting taps. Instead of subclassing ItemizedOverlay, subclass Overlay.

privateclassTapOverlayextendsOverlay {
    publicbooleanonTap(GeoPoint p, MapView mapView) {
        // code that adds item in your ItemizedOverlay// goes herereturntrue;
    }
}

Post a Comment for "How To Add A Marker When I Touch The Map In Android ?"