开发者

I want to display location based information when overlay on map is clicked using android

I am designing the following application.

It shows several overlays on different places on map. I want some code that will show text information (location specific), when an overlay is clicked.

It's not just small text; a huge amount of da开发者_开发技巧ta is associated with every overlay.

For example: To display hotel information about: Bangalore, Mumbai, Delhi, etc.


Use the popular android-mapviewballoons overlay. When an item is tapped a info bubble is displayed. Tapping on the bubble can also do other things.


In your itemized overlay you can override the onTap event and display a dialog:

    @Override
protected boolean onTap(int index) {
    MyOverlayItem item = mOverlays.get(index);
    AlertDialog.Builder dialog = new AlertDialog.Builder(context);
    dialog.setTitle(item.getTitle());
    dialog.setMessage(item.getSnippet());
    dialog.setPositiveButton("OK", new OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    dialog.show();
    return true;
}

This just displays the snippet and title from the overlay item, but you could add other logic to build and format the dialog message.

Edit:

If you have defined a constructor in your MyObject class that takes some key value,

and you have defined a proper

public boolean equals(Object obj) { }

in your MyObject class that will compare on that key value, and you have a either a

LinkedList<MyObject> myObjects;

or an

ArrayList<MyObject> myObjects;

you can do something like this:

int loc = myObjects.indexOf(new MyObject(keyValue));
if (loc != -1) {
myObject = myObjects.get(loc);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜