Different named Markers on Google Android Map

大兔子大兔子 提交于 2019-11-30 00:51:02

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.

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.

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

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. :)

bogdanmogo

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!