Android上谷歌地图上的标记未对齐

时间:2012-02-01 11:37:56

标签: android google-maps google-maps-markers

我在Android APP中的Map Activity上成功放置了许多标记。

问题是当变焦较低时(我在屏幕上看到整个国家),我看到标记根本没有与设定位置对齐。我的意思是,在低变焦水平下,标记似乎距离该点50-100km。

我的标记是一个简单的可绘制图标,中间有一个上边的三角形,所以图标的下角(放置在图标的真正底部中心)应该准确地放在我设置的GPS坐标上为标记。相反,似乎对齐点是图标的左下角...

如何设置marker-icon alignment?

1 个答案:

答案 0 :(得分:1)

自己找到解决方案。 我正在使用标准的Overlay继承类。

我修改了覆盖绘图功能中的指令:

public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
        long when) {
    Point screenPts = new Point();
    mapView.getProjection().toPixels(p, screenPts);
    Point finalDrawPosition= new Point();
    finalDrawPosition.set(screenPts.x - (bmp.getWidth()/2), screenPts.y- bmp.getHeight());

    canvas.drawBitmap(bmp, finalDrawPosition.x, finalDrawPosition.y, null); 
    [...] 
    }