Android:操作方法:显示带有移动当前位置指针的地图(静止图像文件) [英] Android: How To: display a map (still image file) with a moving current location pointer

查看:25
本文介绍了Android:操作方法:显示带有移动当前位置指针的地图(静止图像文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个可以引导一个人到达目的地的原型.

I am trying to create a prototype that could guide a person to his destination place.

  • place 是一栋有好几层楼的宽阔建筑.
  • 我可以获取/检索地图(静止图像).例如当前:1F 目的地:5F;这样我就可以得到 1 楼、2 楼...5 楼的静止图像(5 个图像文件).

场景:

  1. 启动应用程序
  2. 输入当前位置(或者可以使用当前位置自动设置)&目的地
  3. 点击搜索路线按钮搜索要使用的地图(静止图像)&标记当前位置 &​​amp;目的地
  4. 在移动/前往目的地时更新当前位置

问题:

  1. 我只需要一次显示 1 个图像文件(每个楼层),然后使用滚动条移动到其他楼层.但是..不知道如何显示它.
  2. 我可以通过 WiFi 获取当前位置坐标,但不知道如何将其放入静止图像以标记当前位置.
  1. I just need to display 1 image file (each floor) at a time then move to other floor by using scroll bar. But.. don't know how to display it.
  2. I can get the current location coordinate via WiFi but don't know how to put it into still image to mark the current location.

可以肯定,已经有类似的示例应用程序可用.您能否分享概念/想法或包含代码片段.对我的论文有很大帮助.

For sure there is already look a like sample application available. Could you share the concepts/ideas or would you include the code snippets. Big Help with my thesis.

感谢任何有关正确方向的指导.

Any guidance on the right direction is appreciated.

推荐答案

您有几种可能性,创建您自己的类似 MapView 的对象,以在 Google Api 上滚动覆盖您的地图.MapView Api 的示例用法可通过位置开发指南获得.

You have a couple possibilities, create your own MapView like object to provide scrolling ot overlay your map on the Google Api. Example usage of the MapView Api is available through the Location dev guide.

如果您了解缩放和平移的基本图形编程和转换,那么通过您自己的视图执行此操作会更容易.(如果你擅长数学,学起来不会有困难).使用带有 android:scaleType="matrix" 的 ImageView 覆盖 MotionEvent 处理程序以获取触摸,然后将它们处理为平移和缩放矩阵.

To do this via your own View will be easier if you understand basic graphics programming and transformations for zoom and pan. (If you're good at math it will be no trouble to learn). Use an ImageView with android:scaleType="matrix" override the MotionEvent handler to get the touches then process them into a tranlation and zoom matrix.

为了将指示器与图像相关联,将两个像素变成与现实生活中的纬度/经度对应的锚点.通常是矩形图像的 (0,0) 和 (width,height).让您的生活更轻松,并确保图像按比例缩放.然后使用第二个 ImageView(用于指示器)将其绘制在顶部并将其移动到屏幕上的正确位置,并确保此视图中的背景和指示器的背景一样透明,否则您将有一个矩形块晕".

To associate the indicator to the image make two pixels into anchor points that coorespond to a real life lat/long. Usually its (0,0) and (width,height) of a rectangular image. Make your life easier and make sure the images are to scale. Then using a second ImageView (for the indicator) draw it on top and move it to the correct place on the screen and make sure the background in this View is transparent as well as the background of your indicator or you'll have a rectangular block "halo".

请务必检查 LocationManager 给出的每个位置的准确性.

Be sure to check the accuracies of each location given by the LocationManager.

附加内容

onCurrentPosition(Location current){
    double hypotenuse = upperLeft.distanceTo(current);
    double bearing = upperLeft.bearingTo(current);
    double currentDistanceX = Math.cos(bearing) * hypotenuse;
    //                     "percentage to mark the position"
    double currentPixelX = (currentDistanceX / upperLeft.distanceTo(lowerRight) * Math.cos(upperLeft.bearingTo(lowerRight))) * mapWidth;

    moveIndicatorX(currentPixelX);
}

这篇关于Android:操作方法:显示带有移动当前位置指针的地图(静止图像文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆