Search code examples
androiddictionaryandroid-mapviewosmdroid

Osmdroid, how to create a static overlayitem that remains at the center of the map


I've searched high and low to find out how i can put an overlayitem that is not fixed to a GeoPoint (i.e geographical coordinates), but rather stays at a fixed point in the view (e.g. the center of the MapView) regardless of moving/scrolling in the map.

MapView has an .addView() method. I tried creating a view with a drawable but the view will be fixed on the map, exactly like an overlayitem, which is not what i want.

Can anyone help me?


Solution

  • Make a framelayout with your map and a View. Fill a background in your view, and center it horizontally and vertically to make the background centered over your map.

    <FrameLayout 
           android:id="@+id/form_lin_map"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical"
           android:layout_gravity="center_horizontal|center_vertical">
    
           <org.osmdroid.views.MapView
            android:id="@+id/form_mapView"
            android:layout_width="fill_parent"
            android:layout_height="220dp"
            android:enabled="true"
            android:clickable="true"
            android:paddingBottom="10dp"
            />
    
            <View
             android:id="@+id/form_View"
             android:layout_width="40dp"
             android:layout_height="40dp"
             android:layout_gravity="center_horizontal|center_vertical"
             android:background="@drawable/cross" />
        </FrameLayout>'