Android: map overlay shortcuts

I am creating a MapView and I want my custom overlay elements to display the name of the location that they mark when the user clicks on them, such as the Android Maps application.

I am setting up an onTap listener and a floating TextView to store the location name. I still need to configure it so that it redraws the label when the user moves the map, etc.

In any case, I wonder if I invent the wheel here. Is there a built-in method that I don't know about? I think most MapView implementations have labels.

For reference, my implementation so far:

in xml map:

<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 onFocus activity:

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);
    }
}
+3
source share
1

, MapView .

, Google Map , , , . , . , , , - . .

+3

Source: https://habr.com/ru/post/1737070/


All Articles