Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Keep in mind that it's not an ideal approach, because the text on the map is a static image and will rotate along with the map tiles (at some point it will be upside down).</p> <p>Here's an example of how to put the <code>MapView</code> into your own <code>Layout</code> widget and rotate it. I've done it with the OpenStreetMaps, but it should be quite the same for Google Maps.</p> <p>First create the "rotating" <code>Layout</code> widget</p> <pre><code>package com.eli.util; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.widget.LinearLayout; public class RotatingLinearLayout extends LinearLayout { private final int mDiagonal; private float mBearing; public RotatingLinearLayout(final Context pContext, final AttributeSet pAttrs) { super(pContext, pAttrs); final DisplayMetrics dm = pContext.getResources().getDisplayMetrics(); mDiagonal = (int) Math.hypot(dm.widthPixels, dm.heightPixels); } public void setBearing(final float pBearing) { mBearing = pBearing; } @Override protected void dispatchDraw(final Canvas pCanvas) { pCanvas.rotate(-mBearing, getWidth() &gt;&gt; 1, getHeight() &gt;&gt; 1); super.dispatchDraw(pCanvas); } @Override protected void onMeasure(final int pWidthMeasureSpec, final int pHeightMeasureSpec) { final int widthMode = MeasureSpec.getMode(pWidthMeasureSpec); final int heightMode = MeasureSpec.getMode(pHeightMeasureSpec); super.onMeasure(MeasureSpec.makeMeasureSpec(mDiagonal, widthMode), MeasureSpec.makeMeasureSpec(mDiagonal, heightMode)); } } </code></pre> <p>Surround by it your <code>MapView</code> in the <code>layout.xml</code></p> <pre><code>&lt;com.eli.util.RotatingLinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/rotating_layout"&gt; &lt;org.osmdroid.views.MapView android:id="@+id/map_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true"/&gt; &lt;/com.eli.util.RotatingLinearLayout&gt; </code></pre> <p>Now, every time you receive a geo fix, update the bearing of the rotating layout and it should turn.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload