views:

96

answers:

2

I am developing an Android mapping application and I have managed to work Google's ItemizedOverlay tutorial into my code. I'm plotting my little circle on the map nicely.

However, I would like to label my tiny symbol with its title -- all the time. I'm going to be dropping a few different symbols on my map and the able to display their labels would be a BIG help. I got the onTap method working, but when you tap the screen, it takes over the whole display -- which is not very helpful.

I haven't managed to find a thing about this on the internet, so I'm not optimistic, but if anybody's got any sort of suggestion, that would be much appreciated.

A: 

Not sure what onTap has to do with this or what you mean by "it takes over the whole display," but I think to display labels you'll have to draw them yourself. You could do this in a couple ways. One would be to override the ItemizedOverlay.draw method directly, and iterate through each one of your GeoPoints and draw the title directly onto the Canvas at some small offset to that location. Another possible way would be to return a custom marker; instead of just returning the symbol, you could create a Picture by drawing the circle and then drawing some text next to it, and then you would be able to wrap this in a PictureDrawable and use that as the marker for your overlay item.

Neil Traft
onTap: When I tap on the mapped symbol, the title is displayed, but in a manner that obscures the map (essentially). Other than that, it's not doing much I suppose, other than that I am sure the data is in the application.I'll take a stab
Rich
Oops, I hit return before I was done... Continuing: I'll see what I can do with ItemizedOverlay.draw, thanks for the hint.
Rich
Now it's time for you to teach me ;-) -- how do you display the title in `onTap`? I'm doing this too, but I had to do all this extra work where I created a `TextView` and I change the `LayoutParams` on the view so that it is centered over whichever marker the user taps on. Did you find some way of having the overlay automatically do it for you??
Neil Traft
A: 

My onTap method looks like this:

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;
}

The calling application passes in its context (this) when it instantiates the Itemized Overlay. I'm still not really sure what that means, but I save the passed-in context in mContext, and use it in onTap(). I can't really take credit for it, naturally, since somebody else posted in to the Internet. It does display the Overlay's information on the screen, but (unfortunately for me) not in a manner that I'm happy with.

I'm working on overriding the draw method, but that's been much interrupted and is still in its early stages. I'll post it here if there's any interest.

R.

Rich
Update for Neil: The draw method is overridden, and it appears to be functioning nicely. My app nicely draws little labels next to my little symbols and I'm very happy with it. Let me know if you're interested in the code.
Rich
Ah, I understand now, I didn't realize you were using a dialog. Glad to hear you figured out something that works better!
Neil Traft