ItemizedOverlay help

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

ItemizedOverlay help

Postby prodeveloper » Sun Apr 11, 2010 1:53 am

Hi everyone. I've been trying to follow the Google Map View tutorial here:

http://developer.android.com/resources/ ... pview.html

However, when I get a problem when I add the icons onto the map. I've followed the instructions exactly, and the icon appears on the map. However, the program crashes whenever I click on the icon. I've found the source of the problem, which is in these lines of code in the HelloItemizedOverlay.java file:

@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}

If I comment out the middle stuff, so that it's:

@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
return true;
}

then nothing happens when I click on the icon, but at least it doesn't crash. Does anyone know how to get it working as intended, so that the text appears when you click on the icon?
prodeveloper
Freshman
Freshman
 
Posts: 6
Joined: Sun Apr 11, 2010 1:47 am

Top

Postby nicholas.hauschild » Sun Apr 11, 2010 6:02 pm

Hello prodeveloper,

If you could provide us with a stacktrace, it would be much easier to help diagnose your problem. If you are developing in eclipse, you should be able to get it from the LogCat view that comes with the ADT plugin. Simply run the app, let the exception happen, and then it should be in LogCat.

Good Luck!
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Postby YellowJK » Sun Apr 25, 2010 5:20 pm

your probably doing the same thig i did....

in onCreate() your calling

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


which goes with this constructor

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public HelloItemizedOverlay(Drawable defaultMarker) {
  3.  
  4.   super(boundCenterBottom(defaultMarker));
  5.  
  6. }
  7.  
  8.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4



im going to quote developer.android.com

Now set up the ability to handle touch events on the overlay items. First, you're going to need a reference to the application Context as a member of this class. So add Context mContext as a class member, then initialize it with a new class constructor:


so instead you shoud be calling this in onCreate()

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


which goes with this constructor

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
  3.  
  4.   super(defaultMarker);
  5.  
  6.   mContext = context;
  7.  
  8. }
  9.  
  10.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
YellowJK
Freshman
Freshman
 
Posts: 9
Joined: Fri Apr 09, 2010 12:19 am

Postby JKumar » Thu May 13, 2010 10:59 am

Yes.

As said before, you might be missing the Context object, it has to have a reference.You can test it doing anything that do not require the context object in onTap method
Hope the suggestion helps you
Keep posting .It makes us better to understand Android
User avatar
JKumar
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Thu May 13, 2010 8:17 am
Location: INDIA

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests