1

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
            }
4

3 回答 3

4

我能够使用 setMarker()。见答案#3:

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

于 2010-11-17T03:55:02.010 回答
3

我找到了 setMarker 方法正常工作的解决方案:

Drawable drawable = getResources().getDrawable(R.drawable....);  
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());  
overlayItem.setMarker(drawable); 
于 2012-11-09T09:15:53.863 回答
1

步骤#1:创建你自己的子类OverlayItem

步骤#2:覆盖getMarker()并返回您想要的图像

这是一个演示这个的示例项目。

于 2010-11-15T21:48:39.697 回答