Android: Map Overlay Labels

Posted by karnage on Stack Overflow See other posts from Stack Overflow or by karnage
Published on 2010-03-15T23:52:28Z Indexed on 2010/03/15 23:59 UTC
Read the original article Hit count: 885

Filed under:

I am building a MapView and I want my custom overlay items to display the name of the location they are marking when the user taps them, like the Android Maps app.

I setup the onTap listener and the floating TextView to hold the location name. I still need to set it up so that it redraws the label when the user moves the map, etc.

Anyway, I am wondering if I am reinventing the wheel here. Is there a built-in method I am unaware of? I would think that most implementations of MapView have labels.

For reference, my implementation so far:

in map xml:

<LinearLayout android:id="@+id/mapBubbleWrap"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true">
    <TextView android:id="@+id/mapBubble" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:visibility="gone" 
        android:background="#ffffff" 
        android:textColor="#ff0000"/>
</LinearLayout>

in my extended ItemizedOverlay:

public boolean onTap(int index) {

    this.setFocus( mOverlays.get(index) );      
    return true;
}

in my Activity onFocus:

public void onFocusChanged( ItemizedOverlay overlay, OverlayItem item ) {
    if( item != null) {
        mapBubble.setText(item.getTitle());
        Point newPoint = mapView.getProjection().toPixels(item.getPoint(), null);
        mapBubbleWrap.setPadding(newPoint.x, newPoint.y-10, 0, 0);
        mapBubble.setVisibility(View.VISIBLE);
    }
}

© Stack Overflow or respective owner

Related posts about android