【问题标题】:How to plot current location in a Google Maps Image如何在谷歌地图图像中绘制当前位置
【发布时间】:2012-07-26 06:14:27
【问题描述】:

我想用静止图像地图创建Android App,[自定义地图]

在里面。

1) 当前位置谷歌地图图像(屏幕短)。 [这可能是我们赢得的图纸..] 如下图。

9.94015,76.273953是图片的位置。

在此图像中,蓝色图表示当前位置。

如何做到这一点?

Mercator 可以很轻松地做到这一点,但我在编程方面很新……

我做不到。

如果有人帮助我完成示例项目,我将不胜感激。

【问题讨论】:

  • 您要将蓝点更改为其他图像吗?
  • @Archie。这不是问题..只需标记当前位置..
  • 不确定这是否有帮助,但如果您想要的只是一张图片而不是地图,Google Static Maps API 非常有用,可以拉入一张图片并在其上放置一个标记网址:developers.google.com/maps/documentation/imageapis

标签: android google-static-maps mercator


【解决方案1】:

如果您知道地图坐标(左、右、上下),您可以轻松计算出每个像素代表多少。使用这个和 GPS lat long,只需在正确的像素处画一个圆圈。

所以对于 X 位置:(这不是代码)

Map left = 10 
Map Right = 15
Image Width = 1000 pixels

因此:

each pixel = (15-10)/ 1000
           = 0.005

你在 GPS X 坐标 11.5 所以:

11.5 - 10 = 1.5
1.5 / 0.005 = 300

因此,您需要在图像上 X 轴上 300 像素处绘制圆圈。

重复 Y 坐标。(使用高度、顶部和底部)

【讨论】:

    【解决方案2】:

    你尝试做类似谷歌地图标记的事情吗?如果是这样,那么你需要使用 ItemizedOverlay。您将在网上的 ItemizedOverlay 上找到示例。只需在 Google 上搜索“ItemizedOverlay 上的示例”即可。

    你想在 mapView 上画一个圆形吗?如果是这样,那么这就是你必须做的......编写一个扩展 ItemizedOverlay 的类......在 onDraw 方法中使用此代码

    @Override
    
    public void draw(Canvas canvas, MapView mapView, boolean shadow/*, long when*/) {
    
        super.draw(canvas, mapView, shadow);
    
        Paint paint = new Paint();
        // Converts lat/lng-Point to OUR coordinates on the screen.
        android.graphics.Point myScreenCoords = new android.graphics.Point();
    
        GeoPoint point = new GeoPoint(15340000,75120000);
        mapView.getProjection().toPixels(point, myScreenCoords);
        paint.setStrokeWidth(1);
        paint.setARGB(255, 255, 255, 255);
        paint.setStyle(Paint.Style.STROKE);
    
        paint.setTextSize(20);
        paint.setColor(Color.RED);
        paint.setStrokeWidth(2);
    
    
         canvas.drawText("Here I am...", myScreenCoords.x-10,myScreenCoords.y-48, paint);
        return true;                                                   }
    

    【讨论】:

    • ItemizedOverlay 仅在 mapview rt 上叠加?在这种情况下,我们使用的是当前位置的 .png 图像。我们想在图像上绘制当前位置的一个点(只是标记)。 tnx 回放
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    相关资源
    最近更新 更多