Android地图API第2版自定义标记 [英] android Maps API v2 with custom markers

查看:133
本文介绍了Android地图API第2版自定义标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使地图自定义标记。在API第2我可以设置图标,标题等进行标记。但我想在第一次发病到显示冠军标志。现在,标题显示只有当我录音的标记。在V1是叠加的,但在v2中我并没有发现类似的话。

I want to make maps with custom markers. In API v2 I can set icon, title, etc for markers. But I want to display title with marker at the first onset. Now title displays only when I taping the marker. In v1 was overlays, but in v2 I didn't found anything similar.

编辑: 也许我不太清楚。像 Marker.showInfoWindow()的API只为一个标志作品。在同一时间,我不能显示的信息窗口我所有的标记。无论如何,我需要显示的标题为我所有的标志,而无需等待,而用户点击就可以了。

Edited: Maybe I was not clear enough. Something like Marker.showInfoWindow() in API works only for one marker. I can't show info windows for all of my markers at the same time. Anyway I need to show titles for all of my markers, without waiting while user will tap on it.

推荐答案

我也偶然发现了这个问题。 V2 API是向前迈进了一步,退两步。谷歌,请在标记或使用GoogleMap类添加一条重写'画'的方法,所以我们可以自定义绘制自己。

I have also stumbled upon this problem. V2 API is a step forward, two steps back. Google, please add an overridable 'draw' method on the Marker or GoogleMap classes so we can customize the drawing ourselves.

一个可能的解决方案是动态生成位图,并将其附加到标记。即创建一个画布,插入标记位图,画旁边的标记文本。这涉及到一些痛苦计算(适当画布的大小与标记位图和彼此相邻的文本)。遗憾的是,在没有标记的setIcon方法,所以每次文本更改,新的标记必须创建。这可能是罚款,如果你只需要在地图上的标记,但与几十个标记,这可能是不可行的。也有可能是在动态创建那些位图存储器的问题。样本code(只有文本):

A possible solution is to generate the bitmap on the fly and attach it to the marker. i.e. Create a canvas, insert the marker bitmap, draw the text next to the marker. This involves some painful calculations (the appropriate canvas size with the marker bitmap and the text next to each other). Unfortunately, there's no setIcon method in Marker, so every time the text changes, a new marker has to be created. It may be fine if you just have a marker on the map, but with dozens of markers, this may not be feasible. Also there may be memory issue on creating those bitmaps dynamically. A sample code (with just the text):

Bitmap.Config conf = Bitmap.Config.ARGB_8888; 
Bitmap bmp = Bitmap.createBitmap(200, 50, conf); 
Canvas canvas = new Canvas(bmp);

canvas.drawText("TEXT", 0, 50, paint); // paint defines the text color, stroke width, size
mMap.addMarker(new MarkerOptions()
                                .position(clickedPosition)
                                //.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker2))
                                .icon(BitmapDescriptorFactory.fromBitmap(bmp))
                                .anchor(0.5f, 1)
                                    );

希望,谷歌将添加适当的方法,所以我们可以很容易地做到这一点。妈的,我真的很喜欢新的地图API V2旋转功能。

Hopefully, Google will add the appropriate methods so we can do this easily. Damn, I really like the new Map rotate feature in V2 API.

这篇关于Android地图API第2版自定义标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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