Skip to content Skip to sidebar Skip to footer

MapView Balloons To A DetailView

In my MapView there are shown Balloons like this:http://www.codemobiles.com/forum/code-mobile-topic-4180.html (it´s more or less the same code) What I want: If I press Balloon 1 i

Solution 1:

I am also use this link, http://www.codemobiles.com/forum/code-mobile-topic-4180.html some codes are added,

MyMap.java class

public class MyMap extends MapActivity {

MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
MyItemizedOverlay itemizedOverlay;
//MyItemizedOverlay itemizedOverlay2;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    mapOverlays = mapView.getOverlays();

    // first overlay
    drawable = getResources().getDrawable(R.drawable.marker);
    itemizedOverlay = new MyItemizedOverlay(drawable, mapView);

    GeoPoint point = new GeoPoint((int) (51.5174723 * 1E6),
            (int) (-0.0899537 * 1E6));
    OverlayItem overlayItem = new OverlayItem(point, "Umar Shafique",
            "(here goes 1)");
    itemizedOverlay.addOverlay(overlayItem);

    GeoPoint point2 = new GeoPoint((int) (51.515259 * 1E6),
            (int) (-0.086623 * 1E6));
    OverlayItem overlayItem2 = new OverlayItem(point2, "Abdul Karim",
            "here goes 2");
    itemizedOverlay.addOverlay(overlayItem2);

    mapOverlays.add(itemizedOverlay);

    // second overlay
/*  drawable2 = getResources().getDrawable(R.drawable.marker2);
    itemizedOverlay2 = new MyItemizedOverlay(drawable2, mapView);

    GeoPoint point3 = new GeoPoint((int) (51.513329 * 1E6),
            (int) (-0.08896 * 1E6));
    OverlayItem overlayItem3 = new OverlayItem(point3, "Arslan Ilyas",
            "here goes 3");
    itemizedOverlay2.addOverlay(overlayItem3);

    GeoPoint point4 = new GeoPoint((int) (51.51738 * 1E6),
            (int) (-0.08186 * 1E6));
    OverlayItem overlayItem4 = new OverlayItem(point4, "Ahsan",
            "here goes 4");
    itemizedOverlay2.addOverlay(overlayItem4);

    mapOverlays.add(itemizedOverlay2);*/

    final MapController mc = mapView.getController();
    mc.animateTo(point2);
    mc.setZoom(16);

}

@Override
protected boolean isRouteDisplayed() {
    return false;
}

}

Here I comment some code, because here add two itemizedOverlay , so one is comment.

and MyItemizedOverlay.java class

public class MyItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
private Context c;

public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
    super(boundCenter(defaultMarker), mapView);
    c = mapView.getContext();
}

public void addOverlay(OverlayItem overlay) {
    m_overlays.add(overlay);
    populate();
}

@Override
protected OverlayItem createItem(int i) {
    return m_overlays.get(i);
}

@Override
public int size() {
    return m_overlays.size();
}

@Override
protected boolean onBalloonTap(int index) {
    Toast.makeText(c, "onBalloonTap for overlay index " + index,
            Toast.LENGTH_LONG).show();

    if (index == 0) {
        c.startActivity(new Intent(c.getApplicationContext(),
                NewActivity.class));
    } else {
         c.startActivity(new Intent(c.getApplicationContext(),
         secondNewActivity.class));
    }
    return true;
}

}

Here modification code

  if (index == 0) {
        c.startActivity(new Intent(c.getApplicationContext(),
                NewActivity.class));
    } else {
         c.startActivity(new Intent(c.getApplicationContext(),
         secondNewActivity.class));
    }
    return true;
}

press balloon two , we can change index position. we can pass index position through your intent.

provide your code , that only Easy the Explain.


Solution 2:

In the Itemized Overlay onClick handler, add an intentExtra so you can pass identifying information to your QuoteDetail.class. More than likely you'll want to extend the ItemizedOverlay class with your own class, add member variable(s) that you can use to identify the item. Then simply access these member variables and pass them to QuoteDetail as intentExtras.


Post a Comment for "MapView Balloons To A DetailView"