谷歌Android地图不同的命名标记 [英] Different named Markers on Google Android Map

查看:218
本文介绍了谷歌Android地图不同的命名标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android地图上添加许多不同的标记。我的code工作好为止用相同的覆盖一遍又一遍:

i want to add many different markers on an android map. My code works good so far with the same overlay over and over again:

mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new MyItemizedOverlay(drawable);
OverlayItem overlayItem = new OverlayItem(geoPoint, "foo", "bar");
mapOverlays.add(itemizedOverlay);

这工作正常为止。但每一个标记是一样的。我想现在要做的就是像你看到的那些在谷歌地图的webapp在地图上有不同的标记(名为A标记,下一个B,依此类推)。 我怎样才能做到这一点?我需要一个额外的PNG标记的文件添加到我的应用程序? (marker_a.png,marker_b.png,...),或者是有一个简单的方法来实现这一目标?这也可能是因为将有超过26个结果,这样我可能需要不同颜色的标记。

This works fine so far. But every marker is the same. What I want to do now is having different markers on the map like the ones you see on Google Maps Webapp (a marker named "A", the next one "B", and so on). How can I achieve this? Do I have to add an extra png marker file to my app ? (marker_a.png, marker_b.png,...) or is there a simpler way to achieve this? It could also be that there will be more than 26 results so that i possibly need different colours of the markers.

推荐答案

答案之一提供了解决方案,不同的 ItemizedOverlay 每个标记组。你可以通过调用达到同样的单 ItemizedOverlay overlayItem.setMarker(绘制)

One of the answers provides the solution with different ItemizedOverlay for each marker group. You can achieve the same with single ItemizedOverlay by calling overlayItem.setMarker(drawable)

如果您打算从资源加载您的标记,不要忘记调用:

If you are going to load your markers from resources, don't forget to call:

drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());

在打电话之前 setMarker 。否则标记将不会显示。

before you call setMarker. Otherwise markers will not be shown.

由于标记是类型绘制对象您可以获取他们像任何其他绘制对象,包括创建它们的运行时间。

Since markers are type Drawable you can obtain them like any other Drawable, including creating them run-time.

这篇关于谷歌Android地图不同的命名标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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