Android的:如何:标记当前位置到地图(静像) - SOURCE code,,测试用例,实际,预期产出ADDED [英] Android: How To: mark the current location into a map (still image) - SOURCE CODE,TESTCASE,ACTUAL,EXPECTED OUTPUT ADDED

查看:363
本文介绍了Android的:如何:标记当前位置到地图(静像) - SOURCE code,,测试用例,实际,预期产出ADDED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了另一个问题(<一href="http://stackoverflow.com/questions/7062115/android-how-to-display-a-map-still-image-file-with-a-moving-current-location">How显示的地图(静止图像文件)与移动当前位置)

I have created another question (How to display a map (still image file) with a moving current location)

但它包含两(2)题,所以我需要隔离开来。

But it contains 2 (two) questions, so i need to segregate it.

我想创建一个原型,可以引导人,以他的目的地。

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

  • 将是一个广泛的建筑用几个楼层。
  • 我可以获得/检索地图(静止图像)。 例如。当前:1F目的地:5F;这样我就可以拿到第一,第二...... 5楼的静止图像(5图像文件)。

方案:

  1. 在启动应用程序
  2. 输入当前位置和放大器(或可自动使用当前的位置设置);目的地
  3. 点击搜索路线按钮,搜索地图使用(静止图像)及标记当前的位置和放大器;目的地
  4. 在移动时更新当前的位置/去目的地

问题: 我可以通过WiFi /蜂窝塔/ IP地址,但当前位置的坐标不知道如何把它变成静态图像标记当前的位置。

Problem: I can get the current location coordinate via WiFi/cell tower/ip address but don't know how to put it into still image to mark the current location.

您共享的概念/观点或包含code片段。很大的帮助与我的论文。

Would you share the concepts/ideas or include the code snippets. Big Help with my thesis.

这是朝着正确的方向任何指导的AP preciated。

Any guidance on the right direction is appreciated.

更新

实际的例子和实际,期望的输出,测试案例 (包裹codeS这里已经从mapsforge得到)

Actual Example with Actual,Expected Output,Test Case (parcel of codes here has gotten from mapsforge)

MercatorProjectionClass.java

/**
 * A performance optimized implementation of the spherical Mercator projection.
 */
class MercatorProjectionClass {
    /**
     * Width and height of a map tile in pixel.
     */
    static final int TILE_SIZE = 256;

    /**
     * Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain zoom level.
     * 
     * @param latitude
     *            the latitude coordinate that should be converted.
     * @param zoom
     *            the zoom level at which the coordinate should be converted.
     * @return the pixel Y coordinate of the latitude value.
     */
    static double latitudeToPixelY(double latitude, byte zoom) {
        double sinLatitude = Math.sin(latitude * (Math.PI / 180));
        return (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI))
                * ((long) TILE_SIZE << zoom);
    }

    /**
     * Converts a latitude coordinate (in degrees) to a tile Y number at a certain zoom level.
     * 
     * @param latitude
     *            the latitude coordinate that should be converted.
     * @param zoom
     *            the zoom level at which the coordinate should be converted.
     * @return the tile Y number of the latitude value.
     */
    static long latitudeToTileY(double latitude, byte zoom) {
        return pixelYToTileY(latitudeToPixelY(latitude, zoom), zoom);
    }

    /**
     * Converts a longitude coordinate (in degrees) to a pixel X coordinate at a certain zoom level.
     * 
     * @param longitude
     *            the longitude coordinate that should be converted.
     * @param zoom
     *            the zoom level at which the coordinate should be converted.
     * @return the pixel X coordinate of the longitude value.
     */
    static double longitudeToPixelX(double longitude, byte zoom) {
        return (longitude + 180) / 360 * ((long) TILE_SIZE << zoom);
    }

    /**
     * Converts a longitude coordinate (in degrees) to the tile X number at a certain zoom level.
     * 
     * @param longitude
     *            the longitude coordinate that should be converted.
     * @param zoom
     *            the zoom level at which the coordinate should be converted.
     * @return the tile X number of the longitude value.
     */
    static long longitudeToTileX(double longitude, byte zoom) {
        return pixelXToTileX(longitudeToPixelX(longitude, zoom), zoom);
    }

    /**
     * Converts a pixel X coordinate at a certain zoom level to a longitude coordinate.
     * 
     * @param pixelX
     *            the pixel X coordinate that should be converted.
     * @param zoom
     *            the zoom level at which the coordinate should be converted.
     * @return the longitude value of the pixel X coordinate.
     */
    static double pixelXToLongitude(double pixelX, byte zoom) {
        return 360 * ((pixelX / ((long) TILE_SIZE << zoom)) - 0.5);
    }

    /**
     * Converts a pixel X coordinate to the tile X number.
     * 
     * @param pixelX
     *            the pixel X coordinate that should be converted.
     * @param zoom
     *            the zoom level at which the coordinate should be converted.
     * @return the tile X number.
     */
    static long pixelXToTileX(double pixelX, byte zoom) {
        return (long) Math.min(Math.max(pixelX / TILE_SIZE, 0), Math.pow(2, zoom) - 1);
    }

    /**
     * Converts a pixel Y coordinate at a certain zoom level to a latitude coordinate.
     * 
     * @param pixelY
     *            the pixel Y coordinate that should be converted.
     * @param zoom
     *            the zoom level at which the coordinate should be converted.
     * @return the latitude value of the pixel Y coordinate.
     */
    static double pixelYToLatitude(double pixelY, byte zoom) {
        double y = 0.5 - (pixelY / ((long) TILE_SIZE << zoom));
        return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI;
    }

    /**
     * Converts a pixel Y coordinate to the tile Y number.
     * 
     * @param pixelY
     *            the pixel Y coordinate that should be converted.
     * @param zoom
     *            the zoom level at which the coordinate should be converted.
     * @return the tile Y number.
     */
    static long pixelYToTileY(double pixelY, byte zoom) {
        return (long) Math.min(Math.max(pixelY / TILE_SIZE, 0), Math.pow(2, zoom) - 1);
    }

    private static final byte ZOOM_LEVEL = 14;

    /**
     * @param args
     */
    public static void main(String[] args) {
        // Pixel Coordinate of Chicago,IL
        double pixel_y = 1559345;
        double pixel_x = 1075954;
        // Lat Lng of Chicago,IL
        double lat_y = 41.850033;
        double lng_x = -87.65005229999997; 

        testPixelXYToLatitude(pixel_y, pixel_x, lat_y, lng_x);
        testLatLngToPixelXY(pixel_y, pixel_x, lat_y, lng_x);
    }

    private static void testPixelXYToLatitude(
            double pixel_y, double pixel_x, 
            double lat_y, double lng_x) {

        double actual_lat_y = MercatorProjectionClass.pixelYToLatitude(pixel_y, ZOOM_LEVEL);
        double actual_lng_x = MercatorProjectionClass.pixelXToLongitude(pixel_x, ZOOM_LEVEL);

        String expectedstr_lat_y = Double.toString(lat_y).substring(0, 5);
        String expectedstr_lng_x = Double.toString(lng_x).substring(0, 6);

        String actualstr_lat_y = Double.toString(actual_lat_y).substring(0, 5);
        String actualstr_lng_x = Double.toString(actual_lng_x).substring(0, 6);

        String result = (actualstr_lat_y.equals(expectedstr_lat_y) && actualstr_lng_x.equals(expectedstr_lng_x))?"PASSED":"FAILED"; 
        System.out.println("PixelXYToLatitude test result:" + result);
    }

    private static void testLatLngToPixelXY(
            double pixel_y, double pixel_x, 
            double lat_y, double lng_x) {

        double actual_pixel_y = MercatorProjectionClass.latitudeToPixelY(lat_y, ZOOM_LEVEL);
        double actual_pixel_x = MercatorProjectionClass.longitudeToPixelX(lng_x, ZOOM_LEVEL);

        String expectedstr_pixel_y = Integer.toString((Double.valueOf(pixel_y).intValue()));
        String expectedstr_pixel_x = Integer.toString((Double.valueOf(pixel_x).intValue()));

        String actualstr_pixel_y = Integer.toString(Double.valueOf(actual_pixel_y).intValue());
        String actualstr_pixel_x = Integer.toString(Double.valueOf(actual_pixel_x).intValue());

        String result = (actualstr_pixel_y.equals(expectedstr_pixel_y) && actualstr_pixel_x.equals(expectedstr_pixel_x))?"PASSED":"FAILED"; 
        System.out.println("LatLngToPixelXY test result:" + result);
    }
}

以上code输出:

Output of the above code:

  • PixelXYToLatitude测试结果:通过
  • LatLngToPixelXY测试结果:通过

我已经在投影类经纬度转换为像素。 我现在的问题是如何使用上述类,以纪念为静止图像给定的经纬度的。

I have already the projection class to convert LatLng to Pixel. My Problem now is on how to mark into still image of a given LatLng using the above class.

这是我的静止图像(芝加哥,IL):

我想提出一个标记(这里的例子,但后来就需要气球更改为更小的指针)

推荐答案

据我了解,你在这里所面临的一些问题。

From what I understood, you are facing a few problems here.

  • 使用离线瓦片地图控制器

  • Use a map controller with offline tiles

标记在地图上的当前位置

Mark the current location on the map

路线从点A用户B点

地图控制器

基本上,在Android上的位置,供应商将被喂了一些全球定位坐标(经度和纬度),您的应用程序,你想要把它后面的背景,使用户有一种视觉上他的位置。您的主意,把静止图像有右,但修正我建议(这是它适用于每一个商业或非商业的,产品的方式)被向放大图分割成较小的部分,使地图控制器就不必装入大型图象到存储器中。 512×512听起来像一个合理的规模(谷歌地图使用了256×256)。较大的图像的这些块被称为砖。

Basically, the location providers on Android will be feeding your application with some global positioning coordinates (longitude and latitude) and you want to put a background behind it so that the user has a visual on his location. Your idea to put a still image there is right, but a correction I would suggest (and this is the way it works on every commercial, or non-commercial, product) is to split the large images into smaller parts, so that the map controller wouldn't have to load a large image into memory. 512 x 512 sounds like a reasonable size (Google maps uses 256 x 256). These chunks of larger images are called tiles.

使用谷歌地图,这是不可能使用离线瓷砖。我已经写如何做到这一点的谷歌地图与 OSMDroid (这是最好的开源替代品)和另一篇文章在ArcGIS(免费地图控制器为Android,商业地图瓦片;一切都是真棒这个控制器,但在我看来,它是装过的论文项目)

With Google maps it's impossible to use offline tiles. I've written a post on how to do that for Google maps with OSMDroid (this is the best open source alternative) and another post with ArcGIS (free map controller for Android, commercial map tiles; everything is awesome with this controller but in my opinion it's too loaded for a thesis project).

因此​​,步骤在这里重现是:

So, the steps to reproduce here are:

  • 在一块大的文件分成几个小部分
  • 找到你的大图像的边缘的精确坐标确切地知道如何命名的瓷砖(图控制器找到需要覆盖视口通过名称的部分砖)
  • 在实现脱机瓷砖供应商,您的图片

的位置提供

这在我看来是最难的部分。你究竟是如何去查找设备在建筑物的确切位置? GPS可以是一扶到一定程度,但它不可能是precise在建筑物反正。 ArcGIS中提供了一个非常漂亮的内置位置提供者,任何其他解决方案,你必须实现它自己。只要你设法克服这个问题,你还可以使用位置提供商提供的高度自动楼层之间切换。

This, in my opinion is the hardest part. How exactly are you going to find the exact position of a device in a building? GPS can be of a help to a certain extent, but it can't be precise in a building anyway. ArcGIS provides you with a very nice built-in location provider, on any other solution you'll have to implement it on your own. As soon as you manage to overcome this problem you can also use the altitude provided by the location providers to switch between the floors automatically.

路由

要重新present与OSMDroid路由线(当然,在ArcGIS以及)是一块巧克力蛋糕:创建​​回合点数组,绘制从一个点一条线到另一个,并将该行的地图。困难的部分是创建一个路由算法,祝你好运!

To represent a routing line with OSMDroid (well, with ArcGIS as well) is a piece of chocolate cake: create an array of turn points, draw a line from one point to another and put that line on the map. The hard part is to create a routing algorithm, good luck with that!

这篇关于Android的:如何:标记当前位置到地图(静像) - SOURCE code,,测试用例,实际,预期产出ADDED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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