回答
看起來正確的機制來做到這一點是延長然後MyLocationOverlay覆蓋drawMyLocation()受保護方法。
下使用的箭頭以顯示其中「你」是和方式的「你」都指向:
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;
}
}
我爲了得到它的工作作出了previuos代碼進行一些修改正確的原因是箭頭指向錯誤的方向並朝相反的方向旋轉。
我改變
matrix.postRotate(mOrientation);
爲
matrix.postRotate(this.getRotation());
,並添加到末尾:
mapView.postInvalidate();
重繪箭頭時,它改變
你是如何實現getRotation()的?謝謝 – marimaf 2011-10-16 22:44:45
'getRotation()'已經在'MyLocationOverlay'中實現了。 – 2012-10-25 13:36:42
好像它改成了getOrientation() – 2012-10-26 09:16:37
- 1. 如何在此處添加自定義圖像標記?
- 2. 您可以在Android的自定義視圖中使用SensorEventListener嗎?
- 3. 在Android中定位自定義地圖
- 4. 如何在onMeasure之後在自定義surfaceview中分配位圖?
- 5. 如何在Outlook自定義列中添加位圖圖像
- 6. 在自定義視圖中處理UITapGestureRecognizer
- 7. 如何使用MyLocationOverlay在MapView上繪製當前GPS位置?
- 8. 如何在actionscript中爲crossdomain.xml指定自定義位置?
- 9. 如何在flyway中使用自定義的sql腳本位置?
- 10. 如何在Gradle中使用自定義Java註釋處理器?
- 11. 如何在Maven 2中使用自定義註釋處理器?
- 12. 如何在自定義BaseAdapter中使用自定義字體
- 13. 如何在自定義WebAuthenticationDetails中使用我的自定義ConfigurationProperties?
- 14. 如何在NVD3圖表中使用自定義圖例
- 15. 如何在圖像菜單項中使用自定義圖標?
- 16. 如何在myview中使用自定義地圖圖像?
- 17. 如何使用此自定義繪圖類?
- 18. 製作自定義位圖字體以供在cocos2d中使用
- 19. ECharts。如何爲您的數據自定義圖表
- 20. 在圖表中使用自定義表
- 21. 在IB中使用自定義視圖
- 22. 在自定義視圖中使用NSViewController
- 23. 如何在PyQt中使用QGraphicsViews中的自定義繪圖?
- 24. 您必須定義此表
- 25. 如果您在Handlebars.js中預編譯自定義幫助程序,您如何註冊自定義幫助程序?
- 26. 如何在Webpack中定義自定義文件名佔位符?
- 27. 如何在Odoo中自定義視圖
- 28. 如何在Firefox中爲掩碼設置自定義位置?
- 29. 如何處理在自定義GridItemRenderer
- 30. 使用自定義位圖圖像爲BWidget
我能夠改變位圖,但旋轉不是working – marimaf 2011-10-16 22:53:12