Problem with onTouchEvent

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Problem with onTouchEvent

Postby tabaprdh » Fri Dec 26, 2008 12:00 pm

hi androidfans,

i hope someone can help me!

i have a map and want to get the geopoint by touching a location in the map,
but the problem is not the calculation, i can get the geopoint by touching the map,
but the problem is i cant move the map, because when i touch it , the listener is fired, so i want to zoom and move too before getting the geopoint , is that possible in android??

regards
tabaprdh
tabaprdh
Freshman
Freshman
 
Posts: 3
Joined: Fri Dec 26, 2008 11:53 am

Top

Postby mortefer » Fri Dec 26, 2008 12:24 pm

Have you tried limiting your listener to fire only for certain events, like i.e. try add the following so that listener reacts only to touch events (not move or anything)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. if(e.getAction() == MotionEvent.ACTION_DOWN) {
  3.  
  4.     //you code here
  5.  
  6.     return true; //event was handled
  7.  
  8. } else {
  9.  
  10.     return false; //event was NOT handled
  11.  
  12. }
  13.  
  14.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
mortefer
Experienced Developer
Experienced Developer
 
Posts: 54
Joined: Sat Dec 20, 2008 11:24 am

Step further

Postby tabaprdh » Fri Dec 26, 2008 1:07 pm

hi thanks for your adice,

im now a step further, i can touch the zoom controls without starting the listener, but moving the map doesnt work, the listener start by moving and touching
tabaprdh
Freshman
Freshman
 
Posts: 3
Joined: Fri Dec 26, 2008 11:53 am

Postby tabaprdh » Fri Dec 26, 2008 3:30 pm

Problem solved!
tabaprdh
Freshman
Freshman
 
Posts: 3
Joined: Fri Dec 26, 2008 11:53 am

Postby mortefer » Fri Dec 26, 2008 5:11 pm

c'mon share the solution :)
mortefer
Experienced Developer
Experienced Developer
 
Posts: 54
Joined: Sat Dec 20, 2008 11:24 am

Postby yorgosg » Wed Jun 24, 2009 5:19 pm

has anyone found this out? I mean seriously, if you have the time to post "problem solved" you might as well post the solution....
yorgosg
Developer
Developer
 
Posts: 35
Joined: Wed Jan 30, 2008 9:53 am

Top

Postby WarrenFaith » Thu Jun 25, 2009 3:43 pm

You should check if the MotionEvent is a move or a click.
Sample:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if (event.getAction() == MotionEvent.ACTION_DOWN) {
  2.  
  3.     //
  4.  
  5. } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
  6.  
  7.     //
  8.  
  9. } else if (event.getAction() == MotionEvent.ACTION_UP) {
  10.  
  11.     //
  12.  
  13. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby kec6227 » Tue Jul 28, 2009 7:35 pm

Instead of that, I just called map.onTouchEvent(event) after my processing. See Code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         map.setOnTouchListener(new OnTouchListener() {
  2.  
  3.             public boolean onTouch(View v, MotionEvent event) {
  4.  
  5.                 int x = (int)(event.getRawX() * event.getXPrecision() * 1E6);
  6.  
  7.                 int y = (int)(event.getRawY() * event.getYPrecision() * 1E6);
  8.  
  9.                
  10.  
  11.                 Projection proj = map.getProjection();
  12.  
  13.                 GeoPoint loc = proj.fromPixels(x, y);
  14.  
  15.                
  16.  
  17.  
  18.  
  19.                 TextView tv = (TextView)findViewById(R.id.point);
  20.  
  21.                 tv.setText(new Integer(map.getOverlays().size()).toString());
  22.  
  23.                 if(mark) {
  24.  
  25.                     addMarker(loc);
  26.  
  27.                     v.invalidate();
  28.  
  29.                 }
  30.  
  31.                 map.onTouchEvent(event);
  32.  
  33.  
  34.  
  35.                
  36.  
  37.                 mark = false;
  38.  
  39.  
  40.  
  41.                 return true;
  42.  
  43.             }
  44.  
  45.         });
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


My only problem is that the GeoPoints I get are not accurate :-\
kec6227
Developer
Developer
 
Posts: 30
Joined: Fri Jul 24, 2009 7:31 pm

Postby loudo » Mon Oct 26, 2009 12:04 pm

Hello
Does it work for you ? because for me the event is triggered just on time. the other click on the map are not fired.
loudo
Freshman
Freshman
 
Posts: 5
Joined: Thu Jul 23, 2009 1:39 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests