Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different named Markers on Google Android Map

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.

like image 839
David Avatar asked Apr 15 '10 19:04

David


People also ask

What do the different markers mean on Google Maps?

Highways and interstates are marked with the route number, and exit numbers are shown in small green boxes. In major urban areas, Google Maps has a real-time traffic mode, showing roads in a range of colors; green means light traffic and red indicates slow, heavy traffic.

What are Android markers?

Markers are objects of type Marker , and are added to the map with the GoogleMap. addMarker(markerOptions) method. Markers are designed to be interactive. They receive click events by default, and are often used with event listeners to bring up info windows.


1 Answers

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.

like image 173
Viktor Brešan Avatar answered Sep 19 '22 15:09

Viktor Brešan