API:http://developer.baidu.com/map/android_refer/overview-summary.html
推荐文章:
http://blog..net/ynxdb2002/article/details/51786246
http://blog..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 getExtraInfo() {
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 getExtraInfo();
}
4.DefaultClusterRenderer类。默认是sdk是没有添加额外信息,所以要自己加:
mRenderer.setOnClusterItemClickListener(mOnClusterItemClickListener);
/**
* Creates markerWithPosition(s) for a particular cluster, animating it if necessary.
*/
private class CreateMarkerTask {
private final Cluster cluster;
private final Set 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 c, Set 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());
markerOptions.extraInfo(item.getExtraInfo());
} else {
markerOptions.position(item.getPosition());
markerOptions.icon(item.getBitmapDescriptor());
markerOptions.extraInfo(item.getExtraInfo());
}
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
方法
限定符和类型
方法和说明
MarkerOptions
anchor(float anchorX,
float anchorY)
设置 marker 覆盖物的锚点比例,默认(0.5f, 1.0f)水平居中,垂直下对齐
MarkerOptions
draggable(boolean draggable)
设置 marker 是否允许拖拽,默认不可拖拽
MarkerOptions
extraInfo(Bundle extraInfo)
设置 marker 覆盖物的额外信息
float
getAnchorX()
获取 marker 覆盖物水平方向锚点比例
float
getAnchorY()
获取 marker 覆盖物垂直方向锚点比例
Bundle
getExtraInfo()
获取marker覆盖物的额外信息
BitmapDescriptor
getIcon()
获取 Marker 覆盖物的图标
LatLng
getPosition()
获取 marker 覆盖物的位置坐标
float
getRotate()
获取 marker 覆盖物旋转角度
java.lang.String
getTitle()
获取 marker 覆盖物的标题
int
getZIndex()
获取 marker 覆盖物的 zIndex
MarkerOptions
icon(BitmapDescriptor icon)
设置 Marker 覆盖物的图标,相同图案的 icon 的 marker 最好使用同一个 BitmapDescriptor 对象以节省内存空间。
boolean
isDraggable()
获取 marker 覆盖物是否可以拖拽
boolean
isPerspective()
获取 marker 覆盖物是否开启近大远小效果
boolean
isVisible()
获取 marker 覆盖物的可见性
MarkerOptions
perspective(boolean perspective)
设置是否开启 marker 覆盖物近大远小效果,默认开启
MarkerOptions
position(LatLng position)
设置 marker 覆盖物的位置坐标
MarkerOptions
rotate(float rotate)
设置 marker 覆盖物旋转角度,逆时针
MarkerOptions
title(java.lang.String title)
设置 marker 覆盖物的标题
MarkerOptions
visible(boolean visible)
设置 marker 覆盖物的可见性
MarkerOptions
zIndex(int zIndex)
设置 marker 覆盖物的 zIndex
5.mark点击事件:
/**
* 地图marker点击
*/
@Override
public boolean onMarkerClick(Marker marker) {
try {
Bundle bun=marker.getExtraInfo();
if(bun!=null){
if(bun.getString("no_infowindow")!=null&&bun.getString("no_infowindow").trim().equals("infowindow")){
JSONObject js=new JSONObject(bun.getString("info"));
LatLng latLng = marker.getPosition();
mInfoWindow = new InfoWindow(show(js), latLng, -47);
mBaiduMap.showInfoWindow(mInfoWindow);
MapStatusUpdate mup=MapStatusUpdateFactory.newLatLng(latLng);
mBaiduMap.animateMapStatus(mup);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return true;
}
5.设置聚合数:
/**
* If cluster size is less than this size, display individual markers.(默认的聚合数)
*/
private static final int MIN_CLUSTER_SIZE = 3;
二:设置聚合数字的背景颜色,设置一个背景纯颜色的圆形:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_maps_50"
android:orientation="vertical" >
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" />