且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的:如何:使用移动当前位置指针显示的地图(静止图像文件)

更新时间:2023-01-23 08:52:31

您有几个可能性,创建你自己的MapView状物体,以提供滚动OT覆盖地图上的谷歌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.

要通过自己的视图做到这一点会更容易,如果你懂得基本的图形编程和转换的缩放和平移。 (如果你擅长数学这将是没有问题的学习)。请使用ImageView的与机器人:scaleType =矩阵覆盖MotionEvent处理程序来获得触摸,然后加工成一个tranlation和变焦矩阵

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.

要在指标的映像关联使两个像素成coorespond到现实生活中的纬度/长锚点。通常它的(0,0)和一个矩形图像的(宽度,高度)。使您的生活更轻松,并确保图像缩放。然后使用第二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);
}