/**
* This is class for touch event, when user touched the screen
* Enough time, user can tag the touched place as user's favorite
* Place, or fix current position and set as destination.
* @ Author xinyan
* @ Date 2011-10-10
*/
Class Touchy extends Overlay {
@ Override
Public boolean onTouchEvent (MotionEvent e, MapView mapView ){
Log. v (TAG, "Touchy is touched ...");
If (MotionEvent. ACTION_DOWN = e. getAction ()){
Start = e. getEventTime ();
X = (int) e. getX ();
Y = (int) e. getY ();
TouchPoint = mMapView. getProjection (). fromPixels (x, y );
Log. v (TAG, "Touchy is touched... and we get touch point .");
}
If (MotionEvent. ACTION_UP = e. getAction ()){
Stop = e. getEventTime ();
}
If (stop-start & gt; 1500 ){
OverlayItem overlayItem = new OverlayItem (touchPoint,
"Pined position", "A new position ");
CustomPinpoint custom = new CustomPinpoint (marker,
StandardActivity. this );
Custom. insertPinpoint (overlayItem );
MMapView. getOverlays (). add (custom );
New AlertDialog. Builder (StandardActivity. this)
. SetIcon (null)
. SetTitle (R. string. whatYouWant)
. SetSingleChoiceItems (
R. array. select_dialog_whatYouWant, 0,
New DialogInterface. OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog,
Int whichButton ){
If (0 = whichButton ){
// User clicked fix my current
// Position choice
} Else if (1 = whichButton ){
// User clicked set as destination
// Choice
}
}
})
. SetPositiveButton (R. string. positive,
New DialogInterface. OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog,
Int whichButton ){
If (0 = whichButton ){
// User clicked fix my current
// Position choice
} Else if (1 = whichButton ){
// User clicked set as destination
// Choice
} Else if (3 = whichButton ){
// User clicked put into favorite
// Choice
}
}
})
. SetNegativeButton (R. string. cancel,
New DialogInterface. OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog,
Int whichButton ){
Dialog. dismiss ();
}
}). Create (). show ();
} // End of if (stop-start> 1500)
Else {
// I think this overrided method shouldn't capture all
// Of the touch events, otherwise we can't control the map.
Return false;
}
Return true;
}
}
Www.2cto.com
/**
* This is a custom class of pin point overlay,
* It means this overlay appears a marker when you click a place on
* The mapview. The StandardActivtiy will use it.
* @ Author xinyan
* @ Date 2011-10-9
*
*/
Public class CustomPinpoint extends ItemizedOverlay <OverlayItem> {
Private final ArrayList <OverlayItem> pinpoints = new ArrayList <OverlayItem> ();
Private Context c;
Public CustomPinpoint (Drawable defaultMarker ){
Super (defamarmarker );
// TODO Auto-generated constructor stub
}
Public CustomPinpoint (Drawable marker, Context context ){
This (marker );
C = context;
}
@ Override
Protected OverlayItem createItem (int I ){
Return pinpoints. get (I );
}
@ Override
Public int size (){
Return pinpoints. size ();
}
Public void insertPinpoint (OverlayItem item ){
Pinpoints. add (item );
This. populate ();
}
}
Note that the location marked here is a new bubble that is generated when you hold down a map.
The key point is the Overlay subclass Touchy, which implements the Touch event response method. We only need to add the Touchy object in the onCreate method, that is, the Overlay layer that implements the Touch event response method, to the Overlays in the MapView, the event response can be implemented. When the event response is completed, we can mark the bubble and get the address, what do we want, and what do we do?
There seems to be a simpler method, that is, mpinpoint overwrites the public boolean onTap (GeoPoint p, MapView mapView) in ItemizedOverlay), never tried. If so, you don't need the Touchy class.
Author: Yan