开发者

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 = 开发者_Python百科new OverlayItem(point, "", element.getTitle());
            if(locationDistance < 50){
                //green
            }
            else if(locationDistance > 50 && locationDistance < 100){
                //yellow
            }
            else if(locationDistance > 100 && locationDistance < 150){
                //blue
            }


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

Different named Markers on Google Android Map


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜