Baidu map mapview long press event

Source: Internet
Author: User
Tags gety

/**
* Inherit from mapview and override ontouchevent to Implement Bubble Processing
* @ Author Hejin
*
*/
Class seeothermapview extends mapview {
Context context;
Geopoint pt;
Float lastx;
Float lasty;
Long lastdowntime;
Boolean mislongpressed;
Boolean misexcute; // determines whether a long-time operation has been performed
Public seeothermapview (context ){
Super (context );
This. Context = context;
// Todo auto-generated constructor stub
}
Public seeothermapview (context, attributeset attrs ){
Super (context, attrs );
This. Context = context;
}
Public seeothermapview (context, attributeset attrs, int defstyle ){
Super (context, attrs, defstyle );
This. Context = context;
}
@ Override
Public Boolean ontouchevent (motionevent event ){
Switch (event. getaction ()){
Case motionevent. action_down:
Lastx = (INT) event. getx ();
Lasty = (INT) event. Gety ();
Lastdowntime = event. getdowntime ();
Misexcute = true;
Break;
Case motionevent. action_move:
Int thisx = (INT) event. getx ();
Int thisy = (INT) event. Gety ();
Long thiseventtime = event. geteventtime ();
// Check whether long-pressing is performed on a non-long-time basis
If (! Mislongpressed ){
Mislongpressed = islongpressed (lastx, lasty, thisx, thisy, lastdowntime, thiseventtime, 1000 );

}
If (mislongpressed ){
// What is done in long-pressed Mode
// Convert pixel coordinates into address coordinates
If (misexcute ){
PT = This. getprojection (). frompixels (thisx, thisy );
// Todo auto-generated method stub
New msgdlg (context, R. drawable. app, "", Pt. getlatitudee6 () + "-" + Pt. getlongitudee6 (), "yes", "no ");
Setposition (Pt. getlatitudee6 (), Pt. getlongitudee6 (), R. drawable. icon_geo );
Misexcute = false;
}
Mislongpressed = false;
} Else {
// What the Mobile mode does
}
Break;
Case motionevent. action_up:
Misexcute = false;
Break;
}
// Obtain the position of the screen click 20.
// Return true;
Return super. ontouchevent (event );
}
 
 
Public void setposition (INT clat, int Clon, int drawableid ){
Geopoint P;
P = new geopoint (clat, clon );
Drawable mark = getresources (). getdrawable (drawableid );
// Create iteminizedoverlay
Itemizedoverlay <overlayitem> itemoverlay = new itemizedoverlay <overlayitem> (mark, this );

// Add iteminizedoverlay to mapview
Itemoverlay. additem (New overlayitem (P, "item0", "itme0 "));
This. getoverlays (). Clear ();
This. getoverlays (). Add (itemoverlay );
This. getcontroller (). setcenter (P );
This. Refresh ();
}
/**
** Determine whether there is a long press * @ Param lastx x coordinate * @ Param lasty y coordinate *
*
* @ Param thisx
* X coordinate when moving *
* @ Param thisy
* Y coordinate when moving *
* @ Param lastdowntime
* Press time *
* @ Param thiseventtime
* Moving time *
* @ Param longpresstime
* Determine the threshold value of a long press time
*/
Static Boolean islongpressed (float lastx, float lasty, float thisx,
Float thisy, long lastdowntime, long thiseventtime,
Long longpresstime ){
Float offsetx = math. Abs (thisx-lastx );
Float offsety = math. Abs (thisy-lasty );
Long intervaltime = thiseventtime-lastdowntime;
If (offsetx <= 5 & offsety <= 5 & intervaltime> = longpresstime ){
Return true;
}
Return false;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.