Android Google Map标记放置 [英] android google map marker placing

查看:97
本文介绍了Android Google Map标记放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用程序中,我需要将标记放置在地图上的确切位置.我将标记固定在地图上的位置为51.507351,-0.127758(伦敦).我使用以下代码来完成工作.

In my Android application I need to place marker at exact position on map. I pin a marker on map with 51.507351, -0.127758 (London) location. I used the following code to do the work.

googleMap.addMarker(new MarkerOptions().position(
        new LatLng(51.507351, -0.127758)).icon(
        BitmapDescriptorFactory.fromBitmap(BitmapFactory
                .decodeResource(getResources(),
                        R.drawable.q_icon))));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
        new LatLng(51.507351, -0.127758), 20));

这是我的标记可绘制图像:

And this my marker drawable image:

现在我的问题是,"Q"符号位于51.507351,-0.127758的位置.我需要在底部箭头开始的位置放置标记.

Now my problem is, the "Q" symbol is placed at the location of 51.507351, -0.127758. I need to place marker at the position where bottom arrow starts.

请看图片,以便您理解我的问题.

Please see the picture so that you can understand my question.

我该怎么做?请帮助我.

How can I do this? please help me.

推荐答案

对于4px x 2px的图像,如何锚定标记的逻辑如下:

The logic behind how the markers are anchored is something like this for a 4px-by-2px image:

        0,0      0.5,0.0        1,0
        *-----+-----+-----+-----*
        |     |     |     |     |
        |     |     |     |     |
  0,0.5 +-----+-----+-----+-----+ 1,0.5
        |     |     |   X |     |           (U, V) = (0.7, 0.6)
        |     |     |     |     |
        *-----+-----+-----+-----*
        0,1      0.5,1.0        1,1

还要考虑到,根据您的位图资源,它的位置可能与您期望的略有不同,因为它们实际上近似于最近的捕捉位置.因此,在上面的示例中,您的锚点将捕捉到该位置:

Also take into consideration that based on your bitmap resource, it could be positioned a little different than you would expect, because they actually approximate to the nearest snap position. So in the example above, your anchor points will snap to this position:

 *-----+-----+-----+-----*
 |     |     |     |     |
 |     |     |     |     |
 +-----+-----+-----X-----+   (X, Y) = (3, 1)
 |     |     |     |     |
 |     |     |     |     |
 *-----+-----+-----+-----*

查看全文

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