How to display user position on custom made map in indoor navigation?

时间:2019-04-08 13:17:39

标签: java android

I am creating a small indoor navigation android application using wifi fingerprinting. Since it is a small scale application I am using a custom made map(which is basically a png image)I want to show the location of the user on a particular spot on the image and update it accordingly as the user moves. So what is the best way to do it?I thought of dividing image like x-y axis and placing the dot on the axis according to value(Tell me this also).

2 个答案:

答案 0 :(得分:0)

It involves a lot of Bitmap manipulation . Take that marker as an ImageView which you should be able to put it across your FrameLayout inside which you would have the root Map imageView/ map view and then over the top of it . you should be able to put that marker on top of it. but if its a static marker image. then you should be able to use LayoutParams and put on top of the root map view.

答案 1 :(得分:0)

There are hundreds of ways.

One easy way would be to use: https://github.com/chrisbanes/PhotoView

That lib handles scaling, panning, etc and even provides access to the matrix used.

It is important to note too that the users coordinates need to be translated into scale.

In one of my apps, I dont handle user locations, but I allow a user to put pins on the map. My Pin object contains XY coords relative to the original map size.

To convert to the device/image scale size, I do this:

float[] convertedPin = {pin.getX(), pin.getY()};

getImageMatrix().mapPoints(convertedPin);

getImageMatrix() is provided with the library posted above.

Then, I modified the libs onDraw():

for (Pin pin :  pins) {

        if (pin.isVisible()) {

            float[] goal = {pin.getX(), pin.getY()};

            getImageMatrix().mapPoints(goal);

            if (pin.getPinBitmap() != null) {

                float pinSize = TypedValue.applyDimension(COMPLEX_UNIT_DIP, pin.getPinSize(), getContext().getResources().getDisplayMetrics());

                canvas.drawBitmap(pin.getPinBitmap(), goal[0] - (pinSize / 2f), goal[1] - pinSize, null);

            }

            canvas.save();

        }

    }