有沒有什麼常用的方法可以在Google地圖中實現Android應用的標記羣集?Android中的Google地圖標記羣集
我有大約10000位置的數據庫,並希望在更智能的方式顯示在理想情況下它們不僅僅是一個顯示這是很少超過一個火柴盒大傾銷數千個標記...... ,它應該是可能的從網站URL檢索標記,但我不確定使用通常的異步函數從可用性的角度來看甚至是有意義的。
有沒有什麼常用的方法可以在Google地圖中實現Android應用的標記羣集?Android中的Google地圖標記羣集
我有大約10000位置的數據庫,並希望在更智能的方式顯示在理想情況下它們不僅僅是一個顯示這是很少超過一個火柴盒大傾銷數千個標記...... ,它應該是可能的從網站URL檢索標記,但我不確定使用通常的異步函數從可用性的角度來看甚至是有意義的。
我用這個解決方案,它對我來說工作得很好,我希望它有幫助。
http://code.google.com/p/android-playground-erdao/wiki/PhotSpot
Clusterkraf會爲你工作。示例應用程序中高級模式中的一個選項是在全球範圍內聚集10,000個隨機點。集羣是在後臺線程上完成的,因此即使在較舊的設備上也能很好地工作。使大數據集執行的關鍵是將「擴展邊界因子(透支)」設置爲0.它飛行在我的Galaxy Nexus上。
下面的代碼是爲我工作:
主要類
MapView mMapView;
private GoogleMap googleMap;
ClusterManager<MyItem> mClusterManager;
mClusterManager = new ClusterManager<MyItem>(getActivity(), googleMap);
mMapView = (MapView) v.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();// needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
googleMap = mMapView.getMap();
//below code use in onPost() of Asynctask
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(currentlat,currentlng), 15));
mClusterManager = new ClusterManager<MyItem>(getActivity(), googleMap);
googleMap.setOnCameraChangeListener(mClusterManager);
googleMap.setOnMarkerClickListener(mClusterManager);
CustomRenderer customRenderer = new CustomRenderer(getActivity(), googleMap, mClusterManager);
mClusterManager.setRenderer(customRenderer);
for(int i=0;i<jarray.length();i++)
{
JSONObject jobj_root=jarray.getJSONObject(i);
JSONObject j_j_record=jobj_root.getJSONObject("Record");
lat=j_j_record.getDouble("latitude");
lng=j_j_record.getDouble("longitude");
Location loc1 = new Location("");
loc1.setLatitude(temp_lat);
loc1.setLongitude(temp_lng);
Location loc2 = new Location("");
loc2.setLatitude(lat);
loc2.setLongitude(lng);
float distanceInMeters = loc1.distanceTo(loc2);
if(distanceInMeters<2000)
{
//Toast.makeText(getActivity(), " kresp="+distanceInMeters, 34).show();
MyItem offsetItem = new MyItem(lat,lng);
mClusterManager.addItem(offsetItem);
}
}
CustomRenderer.class
public class CustomRenderer extends DefaultClusterRenderer<MyItem>{
private boolean shouldCluster = true;
private static final int MIN_CLUSTER_SIZE = 1;
public CustomRenderer(Context context, GoogleMap map,ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
// TODO Auto-generated constructor stub
}
public void setMarkersToCluster(boolean toCluster)
{
this.shouldCluster = toCluster;
}
@Override
protected boolean shouldRenderAsCluster(Cluster<MyItem> cluster) {
if(shouldCluster)
{
return cluster.getSize() > MIN_CLUSTER_SIZE;
}
else
{
return shouldCluster;
}
}
}
MyItem.class
public class MyItem implements ClusterItem {
private final LatLng mPosition;
public MyItem(double lat, double lng) {
mPosition = new LatLng(lat, lng);
}
@Override
public LatLng getPosition() {
return mPosition;
}
}