我已经浇过的文档,并没有能够想出解决办法。它甚至有可能?
I've poured over the docs and haven't been able to figure this out. Is it even possible?
请参阅本
它看起来像这样做的正确的机制是延长MyLocationOverlay然后覆盖drawMyLocation()保护方法。
It looks like the correct mechanism to do this is to extend MyLocationOverlay then override the drawMyLocation() protected method.
下面使用一个箭头以显示这里的你是和这道你是指:
The following uses an arrow to show where "you" are and which way "you" are pointing:
package com.example;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Point;
import android.location.Location;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
public class MyCustomLocationOverlay extends MyLocationOverlay {
private Context mContext;
private float mOrientation;
public MyCustomLocationOverlay(Context context, MapView mapView) {
super(context, mapView);
mContext = context;
}
@Override
protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
// translate the GeoPoint to screen pixels
Point screenPts = mapView.getProjection().toPixels(myLocation, null);
// create a rotated copy of the marker
Bitmap arrowBitmap = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.arrow_green);
Matrix matrix = new Matrix();
matrix.postRotate(mOrientation);
Bitmap rotatedBmp = Bitmap.createBitmap(
arrowBitmap,
0, 0,
arrowBitmap.getWidth(),
arrowBitmap.getHeight(),
matrix,
true
);
// add the rotated marker to the canvas
canvas.drawBitmap(
rotatedBmp,
screenPts.x - (rotatedBmp.getWidth() / 2),
screenPts.y - (rotatedBmp.getHeight() / 2),
null
);
}
public void setOrientation(float newOrientation) {
mOrientation = newOrientation;
}
}
上一篇:如何设置图像采用Android PhoneGap的壁纸?如何设置、图像、壁纸、Android
下一篇:ViewPager:递归进入executePendingTransactions递归、ViewPager、executePendingTransactions