views:

897

answers:

2

How do I add a marker on a particular location in the map?

I saw this code that shows the coordinates of the touched location. And I want a marker to pop or be shown in that same location everytime it is touched. How do I do this?

 public boolean onTouchEvent(MotionEvent event, MapView mapView) {   
                if (event.getAction() == 1) {                
                    GeoPoint p = mapView.getProjection().fromPixels(
                        (int) event.getX(),
                        (int) event.getY());
                        Toast.makeText(getBaseContext(), 
                            p.getLatitudeE6() / 1E6 + "," + 
                            p.getLongitudeE6() /1E6 , 
                            Toast.LENGTH_SHORT).show();

                        mapView.invalidate();
                }                            
                return false;
            }
+1  A: 

You want to add an OverlayItem. The Google Mapview tutorial shows how to use it.

RickNotFred
oks! i got it. I can draw markers now. thanks :)
lulala
Great, can you accept the answer so that others looking to answer questions will know that this one has already been answered?
RickNotFred
A: 

hi lulala,

would you be able to post your solution? i've been trying to get it to work and am not having any luck. i've followed the google mapview tutorial as well. any help is appreciated! thank you!

cnbishop