代码之家  ›  专栏  ›  技术社区  ›  Sheehan Alam

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

  •  1
  • Sheehan Alam  · 技术社区  · 15 年前

    我在地图上显示标记。我不确定如何为不同的标记指定不同的可提取资源?

    如果位置距离<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
                }
    
    3 回复  |  直到 15 年前
        1
  •  4
  •   Community Mohan Dere    9 年前

    我可以使用setMarker()。见答案3:

    Different named Markers on Google Android Map

        2
  •  3
  •   Nik Reiman    13 年前

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

    Drawable drawable = getResources().getDrawable(R.drawable....);  
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());  
    overlayItem.setMarker(drawable); 
    
        3
  •  1
  •   CommonsWare    15 年前

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

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

    Here is a sample project 证明这一点。