开发者

What would be an effective way to put a marker drawable on the mapview everytime the user clicks the map

I am playing around with Android MapView and have come across a requirement, where i have to put a marker at the place where the user clicks. in my scenario, the user can pan a map , zoom in and out, and click wherever she likes. in 开发者_Python百科this case, the marker should be put wherever the user is clicking on the map. If a previous marker was there on map, then at click event it should be cleared and be put at the new place. This should repeat every time the case repeats.

In future, I'll be having some more drawables like range representative and a pointer to select range which can be dragged.

I am able to put the marker on the first place, but my code doesn't work when the user clicks anywhere else.

Here's the code for the class that I am using: http://pastebin.com/6idn7VwK The full class extending MapActivity and the one extending the ItemizedOverlay can be found in the link above.

I understand that I might be doing some wrong things, so please correct me.

Thanks!


You should override the onTap method for this type of functionality :

    @Override
    public boolean onTap(GeoPoint point, MapView view) {
         // add your marker to the map by creating an overlayItem and calling addOverlay
    }

 public void addOverlay(OverlayItem overlay) {
     mOverlays.add(overlay);
     populate();
 } 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜