Android_百度地图,点聚合功能,点击事件&&设置聚合数字的背景颜色

API:http://developer.baidu.com/map/android_refer/overview-summary.html

推荐文章:

http://blog.csdn.net/ynxdb2002/article/details/51786246

http://blog.csdn.net/aconghui/article/details/50958715

SDK下载:

http://lbsyun.baidu.com/sdk/download

秘钥申请:

http://developer.baidu.com/map/geosdk-android-key.htm

总结:

点聚合功能不是更新jar包,而是将下载的sdk项目BaiduMapsApiDemo里面所需要的src,xml,styles.xml整合。

附:

一:点击mark的时候,显示额外的信息。

1.添加mark:

itemsList.add(new MyItem(shop_ll,shop_type,bun));

2.设置每个mark

/**
     * 每个Marker点,包含Marker点坐标,图标和额外信息
     */
    public class MyItem implements ClusterItem {
        private final LatLng mPosition;
        private String shop_type;
        private Bundle buns;

        public MyItem(LatLng latLng) {
            mPosition = latLng;
        }
        
        public MyItem(LatLng latLng,String shopType,Bundle bun) {
            mPosition = latLng;
            shop_type=shopType;
            buns=bun;
        }

        @Override
        public LatLng getPosition() {
            return mPosition;
        }
        
        @Override
        public Bundle <strong><span style="color:#6600CC;">getExtraInfo</span></strong>() {
            return buns;
        }

        @Override
        public BitmapDescriptor getBitmapDescriptor() {
        	if (shop_type.trim().equals("2")) {
        		return BitmapDescriptorFactory.fromResource(R.drawable.delicacies_logo);
			} else if (shop_type.trim().equals("3")) {
				return BitmapDescriptorFactory.fromResource(R.drawable.shopping_logo);
			} else if (shop_type.trim().equals("4")) {
				return BitmapDescriptorFactory.fromResource(R.drawable.hotel_logo);
			} else if (shop_type.trim().equals("5")) {
				return BitmapDescriptorFactory.fromResource(R.drawable.entertainment_logo);
			} else if (shop_type.trim().equals("6")) {
				return BitmapDescriptorFactory.fromResource(R.drawable.life_service_logo);
			}else{
				return BitmapDescriptorFactory .fromResource(R.drawable.icon_gcoding);
			}
        }
    }

3.接口添加新的抽象方法:

public interface ClusterItem {

    /**
     * The position of this marker. This must always return the same value.
     */
    LatLng getPosition();

    BitmapDescriptor getBitmapDescriptor();
    
    Bundle <strong><span style="color:#FF6666;">getExtraInfo</span></strong>();
    
}

4.DefaultClusterRenderer类。默认是sdk是没有添加额外信息,所以要自己加:

mRenderer.setOnClusterItemClickListener(mOnClusterItemClickListener);

 /**
     * Creates markerWithPosition(s) for a particular cluster, animating it if necessary.
     */
    private class CreateMarkerTask {
        private final Cluster<T> cluster;
        private final Set<MarkerWithPosition> newMarkers;
        private final LatLng animateFrom;

        /**
         * @param c            the cluster to render.
         * @param markersAdded a collection of markers to append any created markers.
         * @param animateFrom  the location to animate the markerWithPosition from, or null if no
         *                     animation is required.
         */
        public CreateMarkerTask(Cluster<T> c, Set<MarkerWithPosition> markersAdded, LatLng animateFrom) {
        	this.cluster = c;
        	this.newMarkers = markersAdded;
        	this.animateFrom = animateFrom;
        }

        private void perform(MarkerModifier markerModifier) {
            // Don't show small clusters. Render the markers inside, instead.
            if (!shouldRenderAsCluster(cluster)) {
                for (T item : cluster.getItems()) {
                    Marker marker = mMarkerCache.get(item);
                    MarkerWithPosition markerWithPosition;
                    if (marker == null) {
                        MarkerOptions markerOptions = new MarkerOptions();
                        if (animateFrom != null) {
                            markerOptions.position(animateFrom);
                            markerOptions.icon(item.getBitmapDescriptor());
                            <span style="color:#FF6666;"><strong>markerOptions.extraInfo(item.getExtraInfo());</strong></span>
                        } else {
                            markerOptions.position(item.getPosition());
                            markerOptions.icon(item.getBitmapDescriptor());
                            <span style="color:#FF6666;"><strong>markerOptions.extraInfo(item.getExtraInfo());</strong></span>
                        }
                        onBeforeClusterItemRendered(item, markerOptions);
                        marker = mClusterManager.getMarkerCollection().addMarker(markerOptions);
                        markerWithPosition = new MarkerWithPosition(marker);
                        mMarkerCache.put(item, marker);
                        if (animateFrom != null) {
                            markerModifier.animate(markerWithPosition, animateFrom, item.getPosition());
                        }
                    } else {
                        markerWithPosition = new MarkerWithPosition(marker);
                    }
                    onClusterItemRendered(item, marker);
                    newMarkers.add(markerWithPosition);
                }
                return;
            }

            MarkerOptions markerOptions = new MarkerOptions()
                    .position(animateFrom == null ? cluster.getPosition() : animateFrom);

            onBeforeClusterRendered(cluster, markerOptions);

            Marker marker = mClusterManager.getClusterMarkerCollection().addMarker(markerOptions);
            mMarkerToCluster.put(marker, cluster);
            mClusterToMarker.put(cluster, marker);
            MarkerWithPosition markerWithPosition = new MarkerWithPosition(marker);
            if (animateFrom != null) {
                markerModifier.animate(markerWithPosition, animateFrom, cluster.getPosition());
            }
            onClusterRendered(cluster, marker);
            newMarkers.add(markerWithPosition);
        }
    }

API:  MarkerOption    com.baidu.mapapi.map.MarkerOptions  

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值