使用OverlayItem.setMarker()设置自定义图标 - Android

时间:2013-01-29 19:38:52

标签: android google-maps overlay itemizedoverlay overlayitem

我正在尝试为地图上的点设置我自己的自定义标记,但它们会一直显示为标记"defaultIcon"

在我的主要:

    itemizedOverlay = new OurItemizedOverlay(defaultIcon, this);

将点添加到地图:

public void addPointToMap(PointOfInterest pointOfInterest) {

            mapOverlays.clear();

            pointOfInterest = setMarkerForPointOfInterest(pointOfInterest);         

            itemizedOverlay.addOverlay(pointOfInterest);
            mapOverlays.add(myLocationOverlay);
            mapOverlays.add(itemizedOverlay);
            mapView.invalidate();
    }

为OverlayItem设置标记

       private PointOfInterest setMarkerForPointOfInterest(PointOfInterest pointOfInterest) {

           String type = pointOfInterest.getType().toLowerCase();

           if(type.equals("monument")) {
               pointOfInterest.setMarker(monumentIcon);
               return pointOfInterest;
           }
           else if(type.equals("building")) {
               pointOfInterest.setMarker(buildingIcon);
               return pointOfInterest;
           }
           else if(type.equals("atm")) {
               pointOfInterest.setMarker(atmIcon);
               return pointOfInterest;
           }
           else if(type.equals("attraction")) {
               pointOfInterest.setMarker(attractionIcon);
               return pointOfInterest;
           }
           else if(type.equals("pub")) {
               pointOfInterest.setMarker(pubIcon);
               return pointOfInterest;
           }
           else if(type.equals("restaurant")) {
               pointOfInterest.setMarker(restaurantIcon);
               return pointOfInterest;
           }
           else if(type.equals("shop")) {
               pointOfInterest.setMarker(shopIcon);
               return pointOfInterest;
           }
           else if(type.equals("bridge")) {
               pointOfInterest.setMarker(bridgeIcon);
               return pointOfInterest;
           }
           else if(type.equals("station")) {
               pointOfInterest.setMarker(stationIcon);
               return pointOfInterest;
           }
           else if(type.equals("cafe")) {
               pointOfInterest.setMarker(cafeIcon);
               return pointOfInterest;
           }
           else if(type.equals("hotel")) {
               pointOfInterest.setMarker(hotelIcon);
               return pointOfInterest;
           }
           else {
               pointOfInterest.setMarker(defaultIcon);
               return pointOfInterest; 
           }

    }

0 个答案:

没有答案