首页 / 浏览问题 / 移动GIS / 问题详情
Android 实时定位与查询的显示问题
4EXP 2017年08月02日

问题:1:仅定位后显示当前位置的图标如,在此基础上添加动态图层以开发查询功能,结果是实时定位能实现,查询功能正常,仅上图位置图标不显示。

   2:在单独实现定位功能时,手机转动上图标“圆”随之转动,三角形不动,如何改成三角形转动,而圆圈不动?

本人代码:

mMapControl.getMap().refresh();
mDynView = new DynamicView(context, mMapControl.getMap());
mView = new CompassView(this);
mapView.addDynamicView(mDynView);
mapView.addView(mView);                    
mGesture = new Gesture(mapView,mDynView);
mPopup = new QueryResultPopup(mapView,mDynView);
mMapControl.getMap().refresh();
mGesture.setSearchAroundListener(new SearchAroundListener() {
  public void searchGeometry(Geometry geoRegion) {
    query(geoRegion, DatasetType.POINT);
  }
 });

CompassView.java:

package com.example.supermarket;

import java.io.InputStream;

import com.supermap.data.Point;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.BitmapFactory.Options;
import android.util.AttributeSet;
import android.view.View;

public class CompassView extends View {

    private Bitmap[] mBitmapArray = new Bitmap[4];
    InputStream is;
    private float[] mValues;
    int[] mBitmapWidth = new int[4];
    int[] mBitmapHeight = new int[4];

    public Point point;

    public Point getPoint() {
        return point;
    }

    public void setPoint(Point point) {
        this.point = point;
    }

    public CompassView(Context context) {
        this(context, null);
        // TODO Auto-generated constructor stub
    }

    public CompassView(Context context, AttributeSet attrs) {
        super(context, attrs);

        BitmapFactory.Options opts = new Options();
        opts.inJustDecodeBounds = false;
        setBitMapArray(context, 0, opts, R.drawable.panel);
        setBitMapArray(context, 1, opts, R.drawable.daohang);

    }

    /**
     * 设置bitmap数组个下标的值
     * 
     * @param index
     * @param opts
     * @param resid
     */
    private void setBitMapArray(Context context, int index,
            BitmapFactory.Options opts, int resid) {
        is = context.getResources().openRawResource(resid);
        mBitmapArray[index] = BitmapFactory.decodeStream(is);
        mBitmapWidth[index] = mBitmapArray[index].getWidth();
        mBitmapHeight[index] = mBitmapArray[index].getHeight();
        mBitmapArray[index + 2] = BitmapFactory.decodeStream(is, null, opts);
        mBitmapHeight[index + 2] = mBitmapArray[index + 2].getHeight();
        mBitmapWidth[index + 2] = mBitmapArray[index + 2].getWidth();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setAntiAlias(true);

        int w = canvas.getWidth();
        int h = canvas.getHeight();

        int cx;
        int cy;
        if(point !=null){
            cx = point.getX();
            cy = point.getY();
        }else
        {
            cx=w/2;
            cy=h/2;
        }

        canvas.translate(cx, cy);
        drawPictures(canvas, 0);

    }

    private void drawPictures(Canvas canvas, int idDelta) {
        if (mValues != null) {
            // Log.d(TAG, "mValues[0] = "+ mValues[0]);
            canvas.rotate(-mValues[0]);
            canvas.drawBitmap(mBitmapArray[0 + idDelta],
                    -mBitmapWidth[0 + idDelta] / 2,
                    -mBitmapHeight[0 + idDelta] / 2, null);
            canvas.rotate(360 + mValues[0]);
            canvas.drawBitmap(mBitmapArray[1 + idDelta],
                    -mBitmapWidth[1 + idDelta] / 2,
                    -mBitmapHeight[1 + idDelta] / 2, null);

        } else {
            canvas.drawBitmap(mBitmapArray[0 + idDelta],
                    -mBitmapWidth[0 + idDelta] / 2,
                    -mBitmapHeight[0 + idDelta] / 2, null);

            canvas.drawBitmap(mBitmapArray[1 + idDelta],
                    -mBitmapWidth[1 + idDelta] / 2,
                    -mBitmapHeight[1 + idDelta] / 2, null);
        }
    }

    public void setValue(float[] value) {
        this.mValues = value;
    }


}

本人参考的源码(查询)

源码(定位)

望大神指导一二!

1个回答

1.定位能显示,说明添加到动态图层上是可行,如果做查询后,不显示了,需要检查下对象是否已添加动态图层里,添加的位置是否是当前地图范围内。

2.三角形旋转,那么将三角形作为一个几何对象,设置它的旋转角度达到显示效果。
1,420EXP 2017年08月02日
谢谢您的回答,我所说的定位能实现是指地图确实在软件运行后缩放到本人当前位置,但是定位的图标没有出现,而且图标是自定义的View,和动态图层都添加到MapView上了,是不是因为动态图层是在最上层,把图标给覆盖了?

三角形的旋转能详细说说吗?用了什么方法实现的?

感谢您的回答
...