Reputation: 20419
I use android-mapviewballoons library to show balloons. So, once user clicks on my marker, balloon is shown.
The question I have: how to display the balloon for particular item without waiting for user click?
Upd. how to identify i? Currently I have the following:
public class Map extends MapActivity {
public void onCreate(Bundle savedInstanceState) {
// here I have extras.getDouble("lat") and extras.getDouble("lng") -
// the location balloon should be shown for
...
itemizedOverlay = new MapOverlay(drawable, mapView);
for (int i = 0; i < items.getCount(); i++) {
// here I add markers, one of them will have lat and lng equal to
// the values passed in extras
public class MapOverlay extends BalloonItemizedOverlay<OverlayItem> {
...
protected OverlayItem createItem(int i) {
Also, with regards to the following code:
// BalloonOverlayView is a raw type. References to generic type BalloonOverlayView<Item> should be parameterized
BalloonOverlayView bov = new BalloonOverlayView(context, 50);
// What is item there? should be getItem(i)?
bov.setData(item);
// The method setPosition(int) is undefined for the type BalloonOverlayView
BalloonOverlayView.setPosition(i);
Upvotes: 1
Views: 5516
Reputation: 397
Try this
itemizedOverlay.onTap(point2, mapView);
you have to identify it through the Geopoint, here is the description
onTap
public boolean onTap(GeoPoint p, MapView mapView)
Handle a tap event. A tap will only be handled if it lands on an item, and have overridden onTap(int) to return true
The balloons library already overwrote it, so you just have to call the onTap method.
Upvotes: 3
Reputation: 8014
Plase refer this tutorial.
In @Override protected OverlayItem createItem(int i)
method you can inflate that ballon ovarlay for your particular index. suppose your specific point is 2 then you can do following in above method
if(i==2){
BalloonOverlayView bov = new BalloonOverlayView(context, 50);
bov.setData(item);
BalloonOverlayView.setPosition(i);
BalloonOverlayView.setGeoPoint(geoPoint);
MapView.LayoutParams params = new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, geoPoint,MapView.LayoutParams.BOTTOM_CENTER);
params.mode=MapView.LayoutParams.MODE_MAP;
mapView.addView(bov, params);
}
Upvotes: 4