Search code examples
javaandroidgoogle-mapsgoogle-maps-api-2itemizedoverlay

How can I show different markers on a map?


I am displaying markers on a map. I am not sure how I can specify a different drawable resource for different markers?

I would like to show a green pin if locations distance < 50, etc. etc.

pin = getResources().getDrawable(R.drawable.pushpin);
        itemizedOverlay = new MyItemizedOverlay(pin, mapView);

        for (Record element : list) {
            GeoPoint point;
            OverlayItem overlayItem;

            double lat = Double.parseDouble(element.getLatitude());
            double lng = Double.parseDouble(element.getLongitude());
            double locationDistance = Double.parseDouble(element.getLocationDist());

            geoPoint.add(new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)));
            listOfOverlays = mapView.getOverlays();
            point = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
            Log.i("deep", "deep    " + point);

            overlayItem = new OverlayItem(point, "", element.getTitle());
            if(locationDistance < 50){
                //green
            }
            else if(locationDistance > 50 && locationDistance < 100){
                //yellow
            }
            else if(locationDistance > 100 && locationDistance < 150){
                //blue
            }

Solution

  • I was able to user setMarker(). See answer #3:

    Different named Markers on Google Android Map