2 onTap methods?

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

2 onTap methods?

Postby prodeveloper » Thu Apr 29, 2010 5:56 am

I'm trying to create a map application that first allows a user to tap on the GoogleMaps screen, and then marking that spot with an ItemizedOverlay object, so I use this method:

@Override
public boolean onTap(GeoPoint p, MapView mapView) {

blah blah

}

However, the result of this method is that on the first user tap, it then generates a bunch of other ItemizedOverlay objects on the map. However, I now want those new ItemizedOverlay objects to have a different onTap method, so in particular, I want to be able to use this version:

@Override
protected boolean onTap(int index) {

when you click on the new ItemizedOverlay objects, something else happens

}

So right now I have both methods in my class. I figure that when the user first taps the screen, the first onTap method is called, and a whole bunch of new ItemizedOverlay objects are created and then added to the map. And when a user then clicks on one of these new ItemizedOverlay objects, then the second onTap method should be called. However, this doesn't seem to be the case, since right now, when I click on those objects, nothing is happening.

Any ideas on what's going on?
prodeveloper
Freshman
Freshman
 
Posts: 6
Joined: Sun Apr 11, 2010 1:47 am

Top

Postby kekomal » Thu Apr 29, 2010 9:32 am

The first onTap calls the second one, by default, but you are overriding it.

I don't know if it is valid for you something like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         @Override
  3.  
  4.         public boolean onTap(GeoPoint p, MapView mapView)  {
  5.  
  6.                 boolean result = super.onTap(p, mapView);
  7.  
  8.                 if(!result) {
  9.  
  10.                         // It was not captured by any ItemizedOverlay
  11.  
  12.                         // Perform your operations and update result if necessary
  13.  
  14.                 } else {
  15.  
  16.                         // Captured by an ItemizedOverlay
  17.  
  18.                 }
  19.  
  20.                 return result;
  21.  
  22.         }
  23.  
  24.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
kekomal
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Mar 17, 2010 10:44 am
Location: Bilbao, Spain

Postby prodeveloper » Thu Apr 29, 2010 8:18 pm

Hey, that actually worked, thanks!

But there's still one thing though, is there anyway that I can still access the index of the ItemizedOverlay object that was tapped, since it's not being passed as an argument? Because I want a slightly different action to occur depending on which ItemizedOverlay object was tapped.
prodeveloper
Freshman
Freshman
 
Posts: 6
Joined: Sun Apr 11, 2010 1:47 am

Postby kekomal » Thu Apr 29, 2010 9:45 pm

The line...

super.onTap(p, mapView);

... should cause, in fact, the call to...

protected boolean onTap(int index)

...whenever the tap is made over an ItemizedOverlay. Just perform the actions associated to an ItemizedOverlay in the second overrided method and the rest of the actions associated to a tap on a clean region of the map in the corresponding part of the if-else clause of the first method.
kekomal
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Mar 17, 2010 10:44 am
Location: Bilbao, Spain

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 6 guests