开发者

Android Mapping Overlay Question

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开发者_JAVA百科 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜