简体   繁体   English

如何在地图上显示不同的标记?

[英]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. 如果位置距离<50,等等,我想显示一个绿色的针脚。

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
            }

I was able to user setMarker(). 我能够使用setMarker()。 See answer #3: 请参阅答案3:

Different named Markers on Google Android Map Google Android地图上的不同名称的标记

I found the solution for the setMarker method to work properly: 我发现setMarker方法可以正常工作的解决方案:

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 步骤#1:创建自己的OverlayItem子类

Step #2: Override getMarker() and return the image you want 步骤2:覆盖getMarker()并返回所需的图像

Here is a sample project demonstrating this. 这是一个演示此的示例项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM