Question

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
            }
Was it helpful?

Solution

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

Different named Markers on Google Android Map

OTHER TIPS

I found the solution for the setMarker method to work properly:

Drawable drawable = getResources().getDrawable(R.drawable....);  
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());  
overlayItem.setMarker(drawable); 

Step #1: Create your own subclass of OverlayItem

Step #2: Override getMarker() and return the image you want

Here is a sample project demonstrating this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top