【问题标题】:Changing position of Custom Info Window of GoogleMap Marker android更改GoogleMap Marker android的自定义信息窗口的位置
【发布时间】:2013-07-16 19:13:35
【问题描述】:

我已向我的 GoogleMap 对象添加了一个自定义 InfoWindow,如下所示

      mMap.setInfoWindowAdapter(new InfoWindowAdapter() 
      {
            @Override
            public View getInfoContents(Marker marker) 
            {
                return null;
            }

            @Override
            public View getInfoWindow(Marker marker) 
            {
                View v = getLayoutInflater().inflate(R.layout.marker_info_window_layout,null,false);
                TextView title = (TextView) v.findViewById(R.id.title);
                TextView desc  = (TextView) v.findViewById(R.id.desc);
                TextView level = (TextView) v.findViewById(R.id.level);
                final int position = Integer.valueOf(marker.getSnippet());

                Players player = playersArray.get(position);
                title.setText(player.name);
                level.setText("Level " + String.valueOf(player.level));
                return v;
            }

效果很好。但是,我的布局的箭头尖端离标记很远。所以我想添加一个偏移量,让我们说至少 50px。

根据此处给出的文档

https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions

anchorPoint : The offset from the marker's position to the tip of an InfoWindow that has been opened with the marker as anchor.

但是当我这样做时

mMap.addMarker(new MarkerOptions()
         .position(p)
         .anchor(0,50)
         .snippet(String.valueOf(position))
         .draggable(false)
         .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

标记只是消失,甚至不显示.. 怎么了?如果没有锚选项,它们可以正常工作。

【问题讨论】:

    标签: java android eclipse


    【解决方案1】:

    目前不可能。如果有人能找到请在此处发布。

    【讨论】:

      【解决方案2】:

      怎么了?

      问题在于您正在阅读 JavaScript API 文档。这就是为什么 URL 中有javascript

      MarkerOptions 的 Android 版 Maps V2 文档告诉 a different story for anchor()

      锚点在连续空间[0.0, 1.0] x [0.0, 1.0]中指定,其中(0, 0)是图像的左上角,(1, 1)是图像的下-右上角。

      【讨论】:

      • 我有一个尺寸为 220 * 75 的 infoWindow 图像,它的锚点在 200*60 现在我想把它放在标记的中间,但它在 0 的最右边。标记。根据上面我尝试设置(0.9f,0.8f)但仍然没有显示标记
      • @MuhammadUmar:我个人没有使用过anchor(),因为我很满意getInfoContents() 而不是getInfoWindow()。我的回答只是指出您最初使用的 (0,50) 值肯定行不通。
      • 在我的例子中,getInforContents 在我的自定义 infoWindow 上显示一个白色矩形,所以我使用了 getInfoWindow
      猜你喜欢
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      • 2013-11-19
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多