【问题标题】:Rotating an image in android using GPS Values pointing to a specific location使用指向特定位置的 GPS 值在 android 中旋转图像
【发布时间】:2011-12-17 14:34:32
【问题描述】:

我正在尝试使用指南针之类的东西,将经度/纬度值传递给它以使其指向特定位置,我的代码可以在移动手机(使用 GPS)以确定位置时绘制箭头。

我想用图片代替绘图

public void draw(Canvas canvas) {
        double angle = calculateAngle(currentLongitude, currentLatitude, targetLongitude, targetLatitude);
        //Correction;
        angle-=90;

    //Correction for azimuth
    angle-=azimuth;

    if((getContext() instanceof Activity) && ((Activity)getContext()).getWindowManager().getDefaultDisplay().getOrientation()==Configuration.ORIENTATION_PORTRAIT)angle-=90;

    while(angle<0)angle=angle+360;

    Rect rect = canvas.getClipBounds();

    int height = rect.bottom-rect.top;
    int width = rect.right-rect.left;
    int left = rect.left;
    int top = rect.top;

}

【问题讨论】:

  • 要实现移动地图吗?
  • 这段代码似乎遗漏了问题的一部分,因为它没有绘制任何东西并且它包含其他问题,比如 if-case 适合的 while 循环

标签: android gps drawing rotation compass-geolocation


【解决方案1】:

你需要做两件事:

  1. Rotate the pointer image
  2. 将生成的位图绘制到屏幕上。

一些技巧,在程序启动时预先旋转图像可能比每次绘制时都旋转图像更快;但是它也会占用更多内存。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多