Google Android 地图上不同命名的标记

发布于 2024-08-29 05:34:55 字数 567 浏览 3 评论 0原文

我想在 Android 地图上添加许多不同的标记。到目前为止,我的代码运行良好,一遍又一遍地使用相同的覆盖层:

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

到目前为止,它运行良好。但每个标记都是一样的。我现在想要做的是在地图上有不同的标记,就像您在 Google 地图 Web 应用程序上看到的那样(一个标记名为“A”,下一个标记为“B”,依此类推)。 我怎样才能实现这个目标?我是否必须向我的应用程序添加额外的 png 标记文件? (marker_a.png,marker_b.png,...)或者是否有更简单的方法来实现这一点?也可能会有超过 26 个结果,因此我可能需要不同颜色的标记。

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);

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

又爬满兰若 2024-09-05 05:34:55

答案之一为每个标记组提供了不同的 ItemizedOverlay 解决方案。您可以通过调用 overlayItem.setMarker(drawable) 使用单个 ItemizedOverlay 实现相同的效果。

如果您要从资源加载标记,请不要忘记在

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

调用之前 调用:调用setMarker。否则将不会显示标记。

由于标记是 Drawable 类型,因此您可以像任何其他 Drawable 一样获取它们,包括在运行时创建它们。

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());

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.

不再让梦枯萎 2024-09-05 05:34:55

这是一个示例项目,在单个ItemizedOverlay。您只需重写一些绘图方法即可处理不同的 PNG。

Here is a sample project showing several different PNGs on a single ItemizedOverlay. You just have to override some of the drawing methods to handle the different PNGs.

蓦然回首 2024-09-05 05:34:55

是的,你需要另一个 png,所以它看起来像这样:

mapOverlays = mapView.getOverlays();

// All "A"s
drawable = this.getResources().getDrawable(R.drawable.marker_a);
itemizedOverlay = new MyItemizedOverlay(drawable);
OverlayItem overlayItem = new OverlayItem(geoPoint, "foo", "bar");
mapOverlays.add(itemizedOverlay);

// All "B"s
drawable = this.getResources().getDrawable(R.drawable.marker_b);
itemizedOverlay = new MyItemizedOverlay(drawable);
OverlayItem overlayItem = new OverlayItem(geoPoint, "foo", "bar");
mapOverlays.add(itemizedOverlay);

Yes, you need another png, so it would look like this:

mapOverlays = mapView.getOverlays();

// All "A"s
drawable = this.getResources().getDrawable(R.drawable.marker_a);
itemizedOverlay = new MyItemizedOverlay(drawable);
OverlayItem overlayItem = new OverlayItem(geoPoint, "foo", "bar");
mapOverlays.add(itemizedOverlay);

// All "B"s
drawable = this.getResources().getDrawable(R.drawable.marker_b);
itemizedOverlay = new MyItemizedOverlay(drawable);
OverlayItem overlayItem = new OverlayItem(geoPoint, "foo", "bar");
mapOverlays.add(itemizedOverlay);
夜司空 2024-09-05 05:34:55

我也遇到了同样的情况,我想对 A、B、C 所插入的引脚进行编号。

好消息是我找到了解决方案。我只创建了一个带有 Pin 背景的 TextView,并动态地向其中插入了一个数字,并将其转换为 Drawable。

您可以使用您想要的引脚颜色背景创建不同的 TextView。

这是我的问题的链接回答道。 :)

I was also stuck in the same situation and I wanted to number the pins insted of A,B,C..

The good News is that I found the solution. I only created a TextView with a Pin background and inserted a number into it dynamically and converted that into Drawable.

You can create different TextView with pin colour background that you want.

Here is the link to my question which I have answered. :)

贪恋 2024-09-05 05:34:55

我使用了这段代码:

 OverlayItem crtItem = new OverlayItem( getPoint( Double.parseDouble(latCoordRow),Double.parseDouble(longCoordRow) ), nameRow , addressRow );

  Drawable crtMarker = markerIconsArray.get(categoryRow); //my current drawable (from a HashMap)
  crtItem.setMarker(crtMarker); // set new marker
  crtMarker.setBounds(0, 0, crtMarker.getIntrinsicWidth(),crtMarker.getIntrinsicHeight()); //setBounds
  boundCenterBottom(crtMarker); //correct shadow problem

如果你不设置边界,你的绘图将不会显示。

I used this code:

 OverlayItem crtItem = new OverlayItem( getPoint( Double.parseDouble(latCoordRow),Double.parseDouble(longCoordRow) ), nameRow , addressRow );

  Drawable crtMarker = markerIconsArray.get(categoryRow); //my current drawable (from a HashMap)
  crtItem.setMarker(crtMarker); // set new marker
  crtMarker.setBounds(0, 0, crtMarker.getIntrinsicWidth(),crtMarker.getIntrinsicHeight()); //setBounds
  boundCenterBottom(crtMarker); //correct shadow problem

If you will not setBounds your drawable won't show.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文